mongodb-query

How to update an embedded document within an embedded document in mongoose?

家住魔仙堡 提交于 2019-12-06 02:53:41
问题 I am building an API in node.js which uses mongodb and mongoose. Currently I have an embedded document within an embedded document (Schema within a Schema) that is simply not persisted to the database, and I have tried all I can but no luck. I have the Schema's defined in mongoose as: var BlogPostSchema = new Schema({ creationTime: { type: Date, default: Date.now }, author: { type: ObjectId, ref: "User" }, title: { type: String }, body: { type: String }, comments: [CommentSchema] }); var

Cleaning orphaned files out of GridFS

流过昼夜 提交于 2019-12-06 02:10:16
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 list of ids results in a Python list that's about 4mb in memory - passing that into a $nin query in

MongoDB: how to compare $size of array to another document item?

白昼怎懂夜的黑 提交于 2019-12-06 01:26:57
MongoDB: how to do something like this, both in mongo console and via JavaScript, Node.js: db.turnys.find( { users:{$size:seats } } ) turnydb.turnys looks like this: [ { "gId": "5335e4a7b8cf51bcd054b423", "seats": 2, "start": "2014-03-30T14:23:29.688Z", "end": "2014-03-30T14:25:29.688Z", "rMin": 800, "rMax": 900, "users": [], "_id": "533828e1d1a483b7fd8a707a" }, { "gId": "5335e4a7b8cf51bcd054b423", "seats": 2, "start": "2014-03-30T14:23:29.688Z", "end": "2014-03-30T14:25:29.688Z", "rMin": 900, "rMax": 1000, "users": [], "_id": "533828e1d1a483b7fd8a707b" }, ... ] Neil Lunn There are real

How to query BsonExtraElements in MongoDB via Linq

删除回忆录丶 提交于 2019-12-06 00:16:36
I used the mongodb [BsonExtraElements] feature to extend my class some dynamic data, but unfortunately I cannot create a query by mongodb C# driver. Here is my model class: public class MongoProductEntity { public MongoProductEntity() { AdditionalColumns = new BsonDocument { AllowDuplicateNames = false }; } [BsonExtraElements] public BsonDocument AdditionalColumns { get; set; } public string BrandName { get; set; } } Here is the query part: var productEntity = new MongoProductEntity () { BrandName = "Brand" }; productEntity.AdditionalColumns.Add("testProperty", 6); productEntity

MongoDB Aggregation Framework - Dynamic Field Rename

白昼怎懂夜的黑 提交于 2019-12-06 00:16:03
问题 I am finding the mongodb aggregation framework to be extremely powerful - it seems like a good option to flatten out an object. My schema uses a an array of sub objects in an array called materials. The number of materials is variable, but a specific field (category) will be unique across objects in the array. I would like to use the aggregation framework to flatten the structure and dynamically rename the fields based on the value of the category field. I could not find an easy way to

Sort and Group in one MongoDB aggregation query

我的未来我决定 提交于 2019-12-05 22:44:12
Using $sort and $group in one aggregation query behaving strangely. Test data: db.createCollection("test"); db.test.insert({ ts : 100, category : 1 }); db.test.insert({ ts : 80, category : 1 }); db.test.insert({ ts : 60, category : 2 }); db.test.insert({ ts : 40, category : 3 }); So when sorting it by ts all looks good, but when I use both $sort and $group result goes in a wrong order. Query: db.test.aggregate([ { $sort : {ts: 1} }, { $group:{"_id":"$category"} } ]); And the result in reverse order: { "_id" : 1 } { "_id" : 2 } { "_id" : 3 } Is it Mongo feature or my misunderstanding? Maby

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

自古美人都是妖i 提交于 2019-12-05 22:18:39
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 }, "profile" : 20, "data" : "....." } ]} How do I query for a particular user and update all the objects in

How can I work with “join” to export data from MongoDB?

旧时模样 提交于 2019-12-05 21:37:15
I have 2 collections: list1 and list2. list1 have some fields and list2 have another fields, including the id referring to list1. I need to do a query to export all items on list1 that have at least one item referring to him on list2. How can I do this? It's something like a join from list1 to list2. I need to run a mongoexport command to generate a csv file. The way I do this is to create a short javascript program that will transfer the data you want to export into a new temporary collection, which you can then export. For example, create a file export.js: //initialise the export results

MongoDB, Multiple count (with $exists)

穿精又带淫゛_ 提交于 2019-12-05 20:33:20
问题 I have these 3 requests: db.mycollection.count({requestA:{$exists:true}}) db.mycollection.count({requestB:{$exists:true}}) db.mycollection.count({requestC:{$exists:true}}) I'd like to make only one request... So i tried the following: db.mycollection.aggregate( [ { $group: { '_id' : { user_id: '$user_id'}, requestA_count: { $sum: { $cond: [ {requestA:{'$exists':true}}, 1, 0 ] } }, requestB_count: { $sum: { $cond: [ {requestB:{'$exists':true}}, 1, 0 ] } }, requestC_count: { $sum: { $cond: [

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

不想你离开。 提交于 2019-12-05 20:23:26
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 got the following class that I'm trying to update public interface IEntity { string Id { get; set; } }