Questions tagged [positional-operator]

23 questions
13
votes
1 answer

Using MongoDB's positional operator $ in a deeply nested document query

Is it possible to use positional operator '$' in combination with a query on a deeply-nested document array? Consider the following nested document defining a 'user': { username: 'test', kingdoms: [ { buildings: [ …
Hugheth
  • 1,802
  • 17
  • 14
7
votes
1 answer

How to toggle a Boolean field in an Array element in MongoDB?

Consider this data { "_id" : ..., "array" : [ { "name" : "value1","flag" : true } , { "name" : "value2","flag" : false } ] } I would like to toggle the 2nd array element (from false to true) I know I can update a…
Eran Medan
  • 44,555
  • 61
  • 184
  • 276
3
votes
2 answers

How to use MongoDB's Postional Operator in C# code?

I want to use the positional operator of the MongoDB in C# code. Here is data structure for Customer: { name:"Robert", age:40, addresses:[ {street:"...", city:"New York", country:"USA", ...}, {street:"...", city:"California",…
sunilkumarba
  • 851
  • 2
  • 9
  • 18
3
votes
0 answers

How to update property of an object that is inside of an Array with mongoose

So, I have a messageThread that has a reference to bunch of messages var messageThreadSchema = new Schema({ chatBetween: [{ type: Schema.Types.ObjectId, ref: 'User' }], messages: [{ type: Schema.Types.ObjectId, ref: 'Message' }], …
m_rd_n
  • 175
  • 2
  • 11
2
votes
2 answers

Incrementing number in an object of mongoose array

I am trying to increment the number in MongoDB using mongoose. But I start failing right at the query stage. When I // @ts-ignore it flows silently with no error but the value doesn't update. The error it throws out is: Type 'number' is not…
user16373392
2
votes
2 answers

bash find, only delete files - order of arguments

Say today is April 8th and I execute the following in bash. cd /tmp mkdir hello touch -d 2015-04-01 hello Then, say I want to delete all files in /tmp that are older than one day, but NOT directories and I execute this: find /tmp -mtime +1 -delete…
Josh Nankin
  • 2,518
  • 4
  • 28
  • 45
2
votes
0 answers

MongoDB positional operator issue

I am trying to run the following update command with a positional operator. businesses.update({ '_acl.5370b9af4a6b2a941ad3bf5e': 'read', 'rooms._id': ObjectId("5370c1ca19b56d0200b26e7f"), _id: ObjectId("5370b9af4a6b2a941ad3bf58") }, { '$set': {…
nabeel
  • 931
  • 9
  • 16
1
vote
1 answer

Mongoid update with Positonal operator not working

I am trying to update the mongodb embedded collection using the $ positional operator from ruby mongoid, but it is not working. Below the mongoid query Viewcounter.collection.update({:item_id=>BSON::ObjectId('yyyy'),'viewinfos.remote_ip' =>…
RameshVel
  • 64,778
  • 30
  • 169
  • 213
1
vote
2 answers

Project a specific field from the first element that matches the query condition on the array

I have a families collection. The documents in it have a users array. Given this family document: { "id" : "1", "users" : [ { "id" : "2", "identities" : [ { "type" :…
OzW
  • 848
  • 1
  • 11
  • 24
1
vote
1 answer

SQR replace by position rather than multiple IF LET ENDIF

In translating codes from one database to the next, I have to use an IF LET ENDIF for each code. IF $CODE = 'A11' LET $CODE = 'AAA' END-IF IF $CODE = 'B11' LET $CODE = 'BBB' END-IF IF $CODE = 'C11' LET $CODE = 'CCC' END-IF. . .ad nauseum Is there a…
dvhouten
  • 55
  • 5
1
vote
3 answers

Print list of lists using *(expansion operator) in single line of code

I am trying to print list lst using a single line of code lst = [("A",23),("B",45),("C",88)] print(*lst, sep="\n") Output comes like this: ('A', 23) ('B', 45) ('C', 88) What I am expecting is A 23 B 45 C 88 However, this can be achieved by the…
1
vote
1 answer

The positional $ operator in MongoDB does not seem to update multiple documents

The following is a modified example from https://docs.mongodb.com/manual/reference/operator/update/positional/#examples db.students.insert([ { "_id" : 1, "grades" : [ 85, 80, 80 ] }, { "_id" : 2, "grades" : [ 88, 90, 92 ] }, { "_id" : 3,…
nawK
  • 693
  • 1
  • 7
  • 13
1
vote
0 answers

MongoError: exception: Cannot apply the positional operator without a corresponding query field containing an array

I am trying to update sub array in following document { "_id" : ObjectId("56b079d937fc13691b25c354"), "clks" : 4, "compl" : 0, "crtd_on" : ISODate("2016-02-02T09:41:45.047Z"), "default" : [], "end_dt" :…
Dineshaws
  • 2,065
  • 16
  • 26
1
vote
2 answers

Example app in C that takes 2 positional parameters

I am looking for an example of a simple app that will use printf to express two different strings based on a positional parameter. In bash I would use: case $1 in -h | --help ) showHelp exit …
Danijel-James W
  • 1,356
  • 2
  • 17
  • 34
0
votes
1 answer

$addToSet in MongoDb with nested positional operators

I want to add a value to an array that is inside another array. My document is like: {categories:[{categoryName:"a category", items:[{itemName:"an item", arrayOfValues:[1]}]}]} I would like to use $addToSet to arrayValues. To do so I am doing an…
Matroska
  • 6,885
  • 14
  • 63
  • 99
1
2