mongodb-query

Mongodb aggregation pipeline size and speed issue

ぐ巨炮叔叔 提交于 2019-12-05 08:34:44
I'm trying to use a mongodb aggregation query to join($lookup) two collections and then distinct count all the unique values in the joined array. *Note: I don't necessarily know what fields(keys) are in the metaDataMap array. And I don't want to count or include fields that might or might not exist in the Map. So that's why the aggregation query looks like it does. So my two collections look like this: events- { "_id" : "1", "name" : "event1", "objectsIds" : [ "1", "2", "3" ], } Objects { "_id" : "1", "name" : "object1", "metaDataMap" : { "SOURCE" : ["ABC", "DEF"], "DESTINATION" : ["XYZ", "PDQ

mongodb group and subgroup counts

﹥>﹥吖頭↗ 提交于 2019-12-05 08:33:10
I have the following document type { "_id" : "-fA2845ORqeyMUItKXfqZw", "user" : "553247ffdc8a4ade4bb09c5e", "state" : 2, "metadata" : { "language" : "en-US" }, "pipeline" : { "api" : "http://localhost:4000", "provider" : 0 }, "ingest" : { "mimetype" : "audio/mpeg", "size" : 92794268, "client" : "computer", "isWriteable" : true }, "assembly" : { "ok" : "ASSEMBLY_EXECUTING", "message" : "The assembly is currently being executed.", "assembly_id" : "23f29680b32911e59d48f358b85e112d", "parent_id" : null, "template_id" : null, "bytes_received" : 1265, "bytes_expected" : null, "upload_duration" : 0

How to Convert mongodb ISODate to string in mongoDB?

爱⌒轻易说出口 提交于 2019-12-05 08:16:37
I have my ISODate in mongo as ISODate and I want to just that in string format with a specific datetime format. Here is the ISODate: ISODate("2020-04-24T11:41:47.280Z") Expected Result: "2020-04-24T11:41:47.280Z" I want this to be happened on mongodb only as many of my services are expecting in this format, and I don't want to make changes in all services as its a tedious job. I got the expected result while i was trying the following. ISODate("2020-04-24T11:41:47.280Z").toJSON() This will give me back the string "2020-04-24T11:41:47.280Z" perhaps simply convert a date into string? this has

SailsJS & MongoDB Aggregation framework troubles with custom queries

僤鯓⒐⒋嵵緔 提交于 2019-12-05 07:04:25
问题 I'm totally new to MongoDB and come from an SQL background. I'm trying to do this : Get the top Artists, based on the number of Dubs. Data Structure : Artists = [ { "dubs": [{...},{...},{...}], "name": "The Doors", "createdAt": "2014-12-15T15:24:26.216Z", "updatedAt": "2014-12-15T15:24:26.216Z", "id": "548efd2a436c850000353f4f" }, { "dubs": [], "name": "The Beatles", "createdAt": "2014-12-15T20:30:33.922Z", "updatedAt": "2014-12-15T20:30:33.922Z", "id": "548f44e90630d50000e2d61d" }, {...} ]

MongoDB search for each dict in list in collection

心已入冬 提交于 2019-12-05 06:47:25
问题 I have a collection containing a list of dicts and I want to search if any dict contains two specific key:values . So for example I want to find_one where a dict contains a specific first and last names. This is my collection: { "names": [ { "firstName": "bob", "lastName": "jones", "age": "34", "gender": "m" }, { "firstName": "alice", "lastName": "smith", "age": "56", "gender": "f" }, { "firstName": "bob", "lastName": "smith", "age": "19", "gender": "m" }, ] } I want to see if there is a

Mongodb remove item from array

人走茶凉 提交于 2019-12-05 06:40:29
I'm trying to remove an element from an array using Java and haven't been successful... I have a "emailsInApp" collection and inside I have this: { "_id" : "750afe", "list" : [ "John@gmail.com", "Mike@gmail.com" ] } { "_id" : "711850", "list" : [ "example@gmail.com" ] } It holds for each id the registered emails. What I would like to do is: given an id and an email, remove that email from that appId. This is what I have atm and when I run it it doesn't change the array at all: DBCollection emailsApp = db.getCollection(EmailsInAppColl); BasicDBObject queryEmail = new BasicDBObject(); queryEmail

How to rename/alias field(s) while fetching it from MongoDB through query using MongoDB-Node.JS native drive?

六眼飞鱼酱① 提交于 2019-12-05 06:34:06
Consider the following code, which I am using to fetch the data from my local MongoDB server. var Db = require('mongodb').Db, MongoClient = require('mongodb').MongoClient, Server = require('mongodb').Server, ReplSetServers = require('mongodb').ReplSetServers, ObjectID = require('mongodb').ObjectID, Binary = require('mongodb').Binary, GridStore = require('mongodb').GridStore, Code = require('mongodb').Code, BSON = require('mongodb').pure().BSON, assert = require('assert'); var db = new Db('test', new Server('localhost', 27017)); db.open(function(err, db) { db.createCollection('simple_limit_skip

mongodb aggregation framework group + project

随声附和 提交于 2019-12-05 06:14:15
问题 I have the following issue: this query return 1 result which is what I want: > db.items.aggregate([ {$group: { "_id": "$id", version: { $max: "$version" } } }]) { "result" : [ { "_id" : "b91e51e9-6317-4030-a9a6-e7f71d0f2161", "version" : 1.2000000000000002 } ], "ok" : 1 } this query ( I just added projection so I can later query for the entire document) return multiple results. What am I doing wrong? > db.items.aggregate([ {$group: { "_id": "$id", version: { $max: "$version" } }, $project: {

Multiple Nested Group Within Array

泄露秘密 提交于 2019-12-05 05:16:04
问题 I'm having group of elements in MongoDB as given below: /* 1 */ { "_id" : ObjectId("58736c7f7d43c305461cdb9b"), "Name" : "Kevin", "pb_event" : [ { "event_type" : "Birthday", "event_date" : "2014-08-31" }, { "event_type" : "Anniversary", "event_date" : "2014-08-31" } ] } /* 2 */ { "_id" : ObjectId("58736cfc7d43c305461cdba8"), "Name" : "Peter", "pb_event" : [ { "event_type" : "Birthday", "event_date" : "2014-08-31" }, { "event_type" : "Anniversary", "event_date" : "2015-03-24" } ] } /* 3 */ { "

Aggregate Group by Date with Daylight Saving Offset

北城以北 提交于 2019-12-05 04:40:02
问题 I'm trying to use mongo aggregation to group documents by the week of a timestamp on each document. All timestamps are stored in UTC time and I need to calculating the week using the clients time not UTC time. I can provide and add the clients UTC offset as shown below but this doesn't always work due to daylight savings time. The offset is different depending on the date and therefore adjusting all the timestamps with the offset of the current date won't do. Does anyone know of a way to