mongodb-query

Unable to update Inner Arraylist object using Mongodb Java Driver

拈花ヽ惹草 提交于 2020-01-06 14:14:31
问题 I have below document structure in mongodb database: { "_id" : ObjectId("52ec7b43e4b048cd48499b35"), "eidlist" : [ { "eid" : "64286", "dst" : NumberLong(21044), "score" : 0 }, { "eid" : "65077", "dst" : NumberLong(21044), "score" : 0 } ], "src" : NumberLong(21047) } I would like to update score field of first object using Java-mongodb driver: I tried following code but it is not working :( : DBObject update_query=new BasicDBObject("src", key).append("eidlist.eid", e.getEdgeid()); DBObject

Comparison query operator ObjectId <-> Date

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-06 12:54:13
问题 Is it possible to execute comparison queries $gt , $lt , etc. of a Date against an ObjectId and vice versa? Does the mongodb driver cast this automatically? Does this mongodb server cast this automatically? 回答1: Yes and no. It is possible under the JavaScript based methods to get a date from the ObjectId value in which you can use for comparisons. It also should be possible to construct an ObjectId given a specific date value as well, but not seeing the utility of that though. But all are

Comparison query operator ObjectId <-> Date

橙三吉。 提交于 2020-01-06 12:53:08
问题 Is it possible to execute comparison queries $gt , $lt , etc. of a Date against an ObjectId and vice versa? Does the mongodb driver cast this automatically? Does this mongodb server cast this automatically? 回答1: Yes and no. It is possible under the JavaScript based methods to get a date from the ObjectId value in which you can use for comparisons. It also should be possible to construct an ObjectId given a specific date value as well, but not seeing the utility of that though. But all are

Morphia - Query based on a subdocument

社会主义新天地 提交于 2020-01-06 08:36:11
问题 I have a mongo collection which has documents which look like below : { "_id" : ObjectId("9873214jkhdkfjdsf8324"), "nm" : "test", "sts" : 1, "updby" : NumberLong(0), "tags" : [ { "name" : "women", "rank" : 1, "type" : 3 }, { "name" : "men", "rank" : 1 }, { "name" : "clothing", "rank" : 2, "type" : 1 } ] } I want to query the collection such that I want all the documents which have "name": "women" and "type" : 3 inside the tags subdocument of each document which is returned. I know that the

MongoDB unknown top level operator: $expr nodejs

天大地大妈咪最大 提交于 2020-01-06 06:51:33
问题 I tried finding solution for this online, but no success. This is the code: Invoice.count( { $expr: {$gt: [ "$totalAmount", "$remainingDebt" ]} } ).exec(callback); where totalAmount and remainingDebt are fields in schema Invoice. The result I get is: "unknown top level operator $expr". I am using mongoose 5.0.11 and mongo lab. Any ideas? 回答1: which version you are Using for the MongoDB since MLab is Providing the Maximum 3.6 version of the Mongo so you need to either modify the Query or

How to get ids of parents based on deeply nested sub document?

末鹿安然 提交于 2020-01-06 05:25:06
问题 This question is in continuation with older question: Parent.save() not working when sub document / deeply nested document is modified Say I have a document as below : { "apiCallCount": 1, "_id": "5e0da052b4b3fe5188602e11", "email": "abc@def.net", "password": "123123", "userName": "username", "companyName": "companyName", "apiKey": "apiKey", "solutionType": "solutionType", "parentCompany": "parentCompany", "buildings": [ { "gateways": [ { "devices": [ { "_id": "5e0da052b4b3fe5188602e15",

How to update an embedded document into a nested array?

旧时模样 提交于 2020-01-06 04:33:36
问题 I have this kind of structure into a Mongo collection : { "_id": "12345678", "Invoices": [ { "_id": "123456789", "Currency": "EUR", "DueTotalAmountInvoice": 768.3699999999999, "InvoiceDate": "2016-01-01 00:00:00.000", "Items": [ { "Item": 10, "ProductCode": "ABC567", "Quantity": 1 }, { "Item": 20, "ProductCode": "CDE987", "Quantity": 1 } ] }, { "_id": "87654321", "Currency": "EUR", "DueTotalAmountInvoice": 768.3699999999999, "InvoiceDate": "2016-01-01 00:00:00.000", "Items": [ { "Item": 30,

mongo query - does property exist?

巧了我就是萌 提交于 2020-01-06 03:32:06
问题 Within a collection document there is a 'sub' property that is an object containing 1 or more properties. The collection looks like: (I've removes extraneous other properties) "properties": { "source": { "a/name": 12837, "a/different/name": 76129 } } I need to do a find on the collection where a/name and a/different/name are variables. The variables have embedded front slashes because they are mqtt topic names, in case you wonder. (node.js) I've tried: collection.find({'properties.source

paging subdocument in mongodb subdocument

北慕城南 提交于 2020-01-05 12:56:10
问题 I want to paging my data in Mongodb . I use slice operator but can not paging my data. I wish to bring my row but can not paging in this row. I want to return only 2 rows of data source. How can resolve it My Query : db.getCollection('forms').find({ "_id": ObjectId("557e8c93a6df1a22041e0879"), "Questions._id": ObjectId("557e8c9fa6df1a22041e087b") }, { "Questions.$.DataSource": { "$slice": [0, 2] }, "_id": 0, "Questions.DataSourceItemCount": 1 }) My collection data : /* 1 */ { "_id" : ObjectId

$pull object from array, and $pull references in another array

喜你入骨 提交于 2020-01-05 12:16:51
问题 Consider this document from a collection of clients: client: { services: [ { _id: 111, someField: 'someVal' }, { _id: 222, someField: 'someVal' } ... // More services ] staff: [ { _id: 'aaa', someField: 'someVal', servicesProvided: [111, 222, 333, ...] }, { _id: 'bbb', someField: 'someVal', servicesProvided: [111, 555, 666, ...] }, { _id: 'ccc', someField: 'someVal', servicesProvided: [111, 888, 999, ...] } ... // More staff ] } A client can have many staff members. Each staff has a reference