mongodb-query

MongoDB/PHP removing a specific array item inside the document

纵然是瞬间 提交于 2019-12-10 12:04:09
问题 Now, I have a document in my collection that I would like to delete on click, and those are comments inside the post document. Here's the structure: { "_id" : "design-patterns-vs-frameworks", "title" : "Design Patterns vs Frameworks", "category" : [ "Frameworks", " Design Patterns", " PHP" ], "date_time" : ISODate("2014-09-02T13:45:29.124Z"), "description" : "Frameworks vs Design Patterns", "content" : " Content!", "author" : "Maciej Sitko", "comments" : [ { "_id" : ObjectId(

How to code MongoDB foreach Query in PHP

这一生的挚爱 提交于 2019-12-10 11:40:00
问题 How to code MongoDB foreach Query in PHP ? Now i have to code the same MONGODB QUERY in PHP with iterator_to_array , i don't know how to get this query to execute in PHP. Now i stucked in this. i have given my data with some example. USED MONGO QUERY: db.getCollection('DRUM').find({'CODE': 'XXYYZZYY'}).forEach( function(doc) { print(doc.COLLECTION.DAY); }); Actual DB RECORD: { "CODE" : "XXYYZZYY", "COLLECTION" : { "DAY" : { "2017-06-05" : { "id" : 565455 }, "2017-06-15" : { "id" : 565445 } },

How to update property in multiple objects in an array for one document in Meteor collection/minimongo?

若如初见. 提交于 2019-12-10 10:07:19
问题 My question is almost a duplicate of this question. The difference is that I am using minimongo within the Meteor framework/platform. Given this document: { "_id" : ObjectId("4d2d8deff4e6c1d71fc29a07"), "user_id" : "714638ba-2e08-2168-2b99-00002f3d43c0", "events" : [ { "handled" : { "name": "Mike", "visible": false }, "profile" : 10, "data" : "....." } { "handled" : { "name": "Shaun", "visible": false }, "profile" : 10, "data" : "....." } { "handled" : { "name": "Glen", "visible": true },

Unable to determine the serialization information for i => i.Id using interfaces

给你一囗甜甜゛ 提交于 2019-12-10 10:00:04
问题 First up, I know there is already questions out there with this error message, but I haven't found any that relate to the use of using interfaces with this type of query. I'm currently trying to update a MongoDB entity using the C# Driver 2.0. However, I'm getting an error when it's trying to build the query (I'm assuming it's the Builders<T>.Filter.Eq(i => i.Id, entity.Id) bit of code) and I'm getting the following error: Unable to determine the serialization information for i => i.Id. I've

Cleaning orphaned files out of GridFS

牧云@^-^@ 提交于 2019-12-10 09:54:27
问题 I have a collection referencing GridFS files, generally 1-2 files per record. The collections are reasonably large - about 705k records in the parent collection, and 790k GridFS files. Over time, there have become a number of orphaned GridFS files - the parent records were deleted, but the referenced files weren't. I'm now attempting to clean the orphaned files out of the GridFS collection. The problem with an approach like suggested here is that combining the 700k records into a single large

How to apply condition on $lookup result in mongoDB?

限于喜欢 提交于 2019-12-10 02:58:36
问题 With the reference of my previous question, I have a question about $lookup with add some conditions. You may get enough reference about question from below link description. Photo: {_id: 1, photo_name: '1.jpg', photo_description: 'description 1', album_id: 1, flag:1 }, {_id: 2, photo_name: '2.jpg', photo_description: 'description 2', album_id: 1, flag:1 }, {_id: 3, photo_name: '3.jpg', photo_description: 'description 3', album_id: 1, flag:1 }, {_id: 4, photo_name: '4.jpg', photo_description:

How do I unset all fields except a known set of fields?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 02:12:03
问题 Suppose I have a single document in my mongo collection that looks like this: { "_id": 123, "field_to_prune": { "keep_field_1": "some value", "random_field_1": "some value", "keep_field_2": "some value", "random_field_2": "some value", "random_field_3": "some value" } } I want to prune that document to look like this: { "_id": 123, "field_to_prune": { "keep_field_1": "some value", "keep_field_2": "some value" } } However, my issue is that I don't know what the "random" field names are. In

Check If field exists in an sub-document of an Array

情到浓时终转凉″ 提交于 2019-12-10 01:43:13
问题 I have a schema that is similar to this. {id: Number, line_items: [{ id: String, quantity: Number, review_request_sent :Boolean }], total_price: String, name: String, order_number: Number } What I want to find is all documents that don't have the field review_request_sent set for all items in the array. Example { id: 1, line_items: [ { id: 43, review_request_sent: true } ] }, { id: 2, line_items: [ { id: 1, review_request_sent: false }, { id: 39 }, ] }, { id: 3, line_items: [ { id: 23, review

Mongodb Aggregate nested subdocuments

久未见 提交于 2019-12-09 23:48:06
问题 Having list of documents [ { "__v" : 21, "_id" : ObjectId("546330dbb8926d177052e9ff"), "code" : "WfvCc", "description" : "", "elements" : [ { "_id" : ObjectId("546471f61e13b76a0b20ccaf"), "comments" : [], "meta" : { "createdBy" : "545ab39ef1b0c88a695fcf8d", "modifiedAt" : "1415868918045", "createdAt" : "1415868918045" }, "title" : "awesome title", "votes" : { "count" : 3, "meta" : [ { "createdBy" : "545ab39ef1b0c88a695fcf8d", "_id" : ObjectId("546473831e13b76a0b20ccb7"), "createdAt" :

MongoDB Aggregation Project check if array contains

情到浓时终转凉″ 提交于 2019-12-09 18:44:03
问题 I have following document: { _id : 21353456, username : "xy", text : "asdf", comments : [ { username : "User1", text : "hi", }, { username : "User2", text : "hi1", }, { username : "User3", text : "hi2", }, { username : "User4", text : "hi3", } ] } Now I want to get the username, text and comments with aggregation and project. In addition I also want a boolean if the comments array contains an username with "User1". I have this, but it doesn't work. db.posttest.aggregate( [ { $project: {