mongodb-query

Best way to read and update mongodb documents using pymongo

筅森魡賤 提交于 2019-12-23 08:35:51
问题 iam trying to read a mongodb collection document by document in order to fetch every record encrypt some of fields in the record and put it back to database. for record in coll.find(): #modifying record here coll.update(record) this is causing a serious problem i.e already updated documents are read again by cursor and same document is processed again in loop (same document is trying to update again) hope this may be one of the solution to the problem. list_coll = [record for record in coll

MongoDB project the documents with count greater than 2 [duplicate]

余生长醉 提交于 2019-12-23 08:04:40
问题 This question already has answers here : Query for documents where array size is greater than 1 (11 answers) Closed 3 years ago . I have a collection like { "_id": "201503110040020021", "Line": "1", // several documents may have this Line value "LineStart": ISODate("2015-03-11T06:49:35.000Z"), "SSCEXPEND": [{ "Secuence": 10, "Title": 1, }, { "Secuence": 183, "Title": 613, }, ... ], } { "_id": "201503110040020022", "Line": "1", // several documents may have this Line value "LineStart": ISODate

Add custom fields in mongodb query

≯℡__Kan透↙ 提交于 2019-12-23 06:04:30
问题 I have a question for this situation with a collection in mongodb this is my Post collection { "_id" : ObjectId("530f67584fb1a510bc18c03f"), "creatorId" : "5f6f2c26-4101-4eae-90d1-20d109bea925", "creationDate" : ISODate("0001-01-01T00:00:00Z"), "category" : 23, "location" : [ -60.67045855832774, 52.86982649605247 ], "replies" : [ { "_id" : ObjectId("531acfc34fb1a50edc86fdcb"), "creatorId" : "0891f887-a6bc-4183-be10-2653b7b45e79" }, { "_id" : ObjectId("531acfc34fb1a50edc86fdcb"), "creatorId" :

Delete an element from an array of an array in MongoDb

耗尽温柔 提交于 2019-12-23 05:37:16
问题 Below is the schema for an array contacts. The contacts array has a field hashtag which is another array. How do I delete an element openLove from the array Hashtags? "contacts" : [ { "addedDate" : ISODate("2015-12-02T09:06:09.891Z"), "personEmailId" : "tell.fadgfdg@gmail.com", "_id" : ObjectId("565eb481bf35eeb83d7f9f13"), "verified" : true, "favorite" : true, "linkedinUserName" : null, "facebookUserName" : null, "twitterUserName" : "IamlifePaul", "count" : 2, "relationshipStrength_updated" :

Need to sum from array object value in mongodb

帅比萌擦擦* 提交于 2019-12-23 05:34:09
问题 I am trying to calculate total value if that value exits. But query is not working 100%. So can somebody help me to solve this problem. Here my sample document. I have attached two documents. Please these documents & find out best solution Document : 1 { "_id" : 1"), "message_count" : 4, "messages" : { "data" : [ { "id" : "11", "saleValue": 1000 }, { "id" : "112", "saleValue": 1400 }, { "id" : "22", }, { "id" : "234", "saleValue": 111 } ], }, "createdTime" : ISODate("2018-03-18T10:18:48.000Z"

mongodb $where query to fetch sub-document content

只愿长相守 提交于 2019-12-23 04:43:10
问题 Below mongodb query is not returning the document. What is wrong with the query? I want to specify $where to match an element in array [EDIT] Above problem is a simplified version of my scenario. I am using a spring data mongodb repository. I want to specify the query using @Query annotation. Was hoping the $where part to be simple comparison and not a full fledged javascript function. something like @Query ( value=" { flag: true, $where: \"this.versions.version == this.defaultVersion \"}",

MongoDb Select Query Issue Whit Regular Expression (Starts whit and Ends Whit)

我的未来我决定 提交于 2019-12-23 03:59:11
问题 I need a regular expression to validate a String like this: 1678;1678;1678;1678 and 1;0;1;1;0;1 I tried to use this pattern: db.getCollection('CollectionName').find( { "magnitude": /^[1678][1678]$/, "flag": /^[1][1]$/ } ) but it doesnt works, i try this two patterns that works separate but not both at the same time db.getCollection('CollectionName').find( { "magnitude": /[1678]$/, "flag": /[1]$/ } ) db.getCollection('CollectionName').find( { "magnitude": /^[1678]/, "flag": /^[1]/ } ) I didnt

Mongoose: Filter collection based on values in another collection

谁说胖子不能爱 提交于 2019-12-23 02:54:40
问题 Consider documents that contain an arrays of ID of another collection, how can I find documents applying a filter based on the related collection using mongoose? I can't find my error Installation.aggregate( [ // Stage 1 { $lookup: { from: "users", localField: "_id", foreignField: "_id", as: "Users" } }, // Stage 2 { $unwind: { path: "$Users" } }, // Stage 3 { $match: {"Users.Email1" : "test@test.com"} }, { $sort: { _id: -1 } }, { $limit: 10 } ] ,function (err, installations) { console.log

MongoDB/Mongoose - Querying an array of objects by date

寵の児 提交于 2019-12-23 02:36:16
问题 I have the following metrics collection: { name: "Hello", values: [ { value: 2629, date: "2016-10-28T07:00:00.000Z", _id: "58453abfef7aaa15ac1fdee8" }, { value: 1568, date: "2016-10-29T07:00:00.000Z", _id: "58453abfef7aaa15ac1fdee7" }, { value: 1547, date: "2016-10-30T07:00:00.000Z", _id: "58453abfef7aaa15ac1fdee6" }, { value: 1497, date: "2016-10-31T07:00:00.000Z", _id: "58453abfef7aaa15ac1fdee5" }, { value: 3031, date: "2016-11-01T07:00:00.000Z", _id: "58453abfef7aaa15ac1fdee4" }, { value:

Meteor: how do I return data from fields in a specific object?

流过昼夜 提交于 2019-12-23 02:30:57
问题 This should be a fairly simple one. myobject has various properties, _id, name, createdBy, date etc In my find query I want to only return specific fields from within myObject. So for example, what would I need to do to modify the find query below so that only name was returned? myCollection.find({createdBy: someId}, {fields: {myObject: 1}}).fetch(); Currently this will return everything in myObject which it should do, I just want one field within myObject returned. 回答1: Here is a way to do