mongodb-query

MongoDB Spark Connector - aggregation is slow

荒凉一梦 提交于 2021-02-06 12:50:32
问题 I am running the same aggregation pipeline with a Spark Application and on the Mongos console. On the console, the data is fetched within the blink of an eye, and only a second use of "it" is needed to retrieve all expected data. The Spark Application however takes almost two minutes according to the Spark WebUI. As you can see, 242 tasks are being launched to fetch the result. I am not sure why such an high amount of tasks is launched while there are only 40 documents being returned by the

MongoDB Spark Connector - aggregation is slow

非 Y 不嫁゛ 提交于 2021-02-06 12:49:07
问题 I am running the same aggregation pipeline with a Spark Application and on the Mongos console. On the console, the data is fetched within the blink of an eye, and only a second use of "it" is needed to retrieve all expected data. The Spark Application however takes almost two minutes according to the Spark WebUI. As you can see, 242 tasks are being launched to fetch the result. I am not sure why such an high amount of tasks is launched while there are only 40 documents being returned by the

Partition data around a match query during aggregation

你。 提交于 2021-02-05 11:18:30
问题 What I have been trying to get my head around is to perform some kind of partitioning(split by predicate) in a mongo query. My current query looks like: db.posts.aggregate([ {"$match": { $and:[ {$or:[{"toggled":false},{"toggled":true, "status":"INACTIVE"}]} , {"updatedAt":{$gte:1549786260000}} ] }}, {"$unwind" :"$interests"}, {"$group" : {"_id": {"iid": "$interests", "pid":"$publisher"}, "count": {"$sum" : 1}}}, {"$project":{ _id: 0, "iid": "$_id.iid", "pid": "$_id.pid", "count": 1 }} ]) This

Update MongoDB field using value of another field

不羁岁月 提交于 2021-02-05 11:12:32
问题 In MongoDB, is it possible to update the value of a field using the value from another field? The equivalent SQL would be something like: UPDATE Person SET Name = FirstName + ' ' + LastName And the MongoDB pseudo-code would be: db.person.update( {}, { $set : { name : firstName + ' ' + lastName } ); 回答1: The best way to do this is in version 4.2+ which allows using of aggregation pipeline in the update document and the updateOne, updateMany or update collection method. Note that the latter has

Update MongoDB field using value of another field

﹥>﹥吖頭↗ 提交于 2021-02-05 11:10:32
问题 In MongoDB, is it possible to update the value of a field using the value from another field? The equivalent SQL would be something like: UPDATE Person SET Name = FirstName + ' ' + LastName And the MongoDB pseudo-code would be: db.person.update( {}, { $set : { name : firstName + ' ' + lastName } ); 回答1: The best way to do this is in version 4.2+ which allows using of aggregation pipeline in the update document and the updateOne, updateMany or update collection method. Note that the latter has

How to group arrays based on another array in mongodb aggregation?

给你一囗甜甜゛ 提交于 2021-02-05 09:42:38
问题 I have seen kind of a similar question, but it has no answer so it doesn't answer my question. How to group arrays based on another array in mongodb aggregation? Assume you have these schemas: PollSchema const PollSchema = new mongoose.Schema({ numberOfChoices: { type: Number, required: true, min: [1, "Number of choices must be at least 1"], max: [10, "Number of choices cannot be more than 10"], }, arrayOfNamesOfChoices:[{ name: { type: String, required: true, }, }], }); CastedVotedSchema

MongoDB filter objects array content based on object member

自闭症网瘾萝莉.ら 提交于 2021-02-05 08:15:27
问题 I have the following objects array and was wondering if there is a way to filter results as return only QtyIn records or return only QtyOut records? Any hint is highly appreciated. Thanks for your help { warehouseID: "1234", transactions : [ { "qtyIn" : "10", "transDateTime" : ISODate("2019-09-10T18:54:41.983Z") }, { "qtyOut" : "11", "transDateTime" : ISODate("2019-08-10T18:54:41.983Z") }, { "qtyOut" : "200", "transDateTime" : ISODate("2019-02-10T11:54:41.983Z") } ], } 回答1: You can compare

MongoDB - Update field in an array object based on nested array's field value

喜夏-厌秋 提交于 2021-02-05 08:13:28
问题 I am trying to update a field inside array of objects, where field in nested array is equal to a value. My goal here is to set the picture field a new url, where value field in valueList is oldRed Product schema: { variations: [{ id: 1, picture: 'https://example.picture.com', valueList: [{ name: 'color', value: 'oldRed' }, { name: 'size', value: 'M' }] }, { id: 2, picture: 'https://example.picture.com', valueList: [{ name: 'color', value: 'black' }, { name: 'size', value: 'M' }] }] } The

How to clone a collection from one MongoDB to another on same server

懵懂的女人 提交于 2021-02-05 08:01:45
问题 I'm using Mongo 3.2. I have two databases on my localhost named client1 and client2 . Now client1 contains a collection named users . I want to clone this collection to client2 . I have tried:- use client2 db.cloneCollection('localhost:27017', 'client1.users', { 'active' : true } ) This outputs { "ok" : 0.0, "errmsg" : "can't cloneCollection from self" } Is cloning a collection from one db to another on the same server prohibited? 回答1: Few things : In general cloneCollection is used for

Mongoose - find(): object inside search options is not working

耗尽温柔 提交于 2021-02-05 07:52:06
问题 I have a mongoose Schema that looks like this: var mySchema = new mongoose.Schema({ ... metadata: { isDeleted: { type: Boolean, default: false }, ... } }); I want to get the list of elements in my mongodb database applying a filter, so I have the following object: var searchOptions = { metadata: { isDeleted: false } }; that always needs to have that metadata.isDeleted value set to false , appart from other parameters that will be added later, before executing the query: var objQuery = myModel