mongodb-query

How to find documents with exactly the same array entries as in a query

和自甴很熟 提交于 2019-12-14 02:19:57
问题 I have documents in a collection, looking like this: [ { userId: 1, itemsIds: [399957190, 366369952], hash: '85e765840b1cd3c413404cdf6b8fb2a4' }, { userId: 2, itemsIds: [349551151, 366369952], hash: 'a28fa334515749b1b13fcd2183edb8de' }, { userId: 3, itemsIds: [399957190, 366369952], hash: '85e765840b1cd3c413404cdf6b8fb2a4' } ] These are users, which have favorite items in their lists. I want one user's list to others and find if they are equal. If they are, I want to mark them as a kind of a

Format date in mongodb query output on shell

£可爱£侵袭症+ 提交于 2019-12-14 00:58:46
问题 I want to format the date time into an specific format on the mongo shell output My query db.getCollection('people').find({ date: { $gte: ISODate("2017-04-24T14:04:34.447Z") } }, { _id: 0, age: 0, } ); My output against this query: /* 1 */ { "user_id" : "bcd020", "status" : "D", "date" : ISODate("2017-04-24T14:04:34.447Z") } /* 2 */ { "user_id" : "bcd021", "status" : "D", "date" : ISODate("2017-04-24T14:04:34.447Z") } What i want is to format the datetime in the output something like, /* 1 */

Get string array from Pymongo query

核能气质少年 提交于 2019-12-13 21:29:34
问题 I need to get an array with the values from the field 'colname'. I can't return a Cursor, just the array of values. Is there a way to query this array without having to loop the Cursor? I feel this is a waste of processing resources. Right now I'm doing this: from pymongo import MongoClient client = MongoClient('mongodb://localhost:27017/') headers = client['headers'] entomo = headers.entomo entomo_data = entomo.find() entomo_array = [] for data in entomo_data: entomo_array.append(data[

How to do multiple aggregation operations in MongoQuery and Update the field in a collection

久未见 提交于 2019-12-13 21:28:14
问题 In RDBMS, suppose we have 4 columns , say col1, col2, col3, col4 If we want col4 value to be col1 + col2 - col3 , we can write an update statement as follows: Update Table set col4=col1+col2-col3 Is doing multiple operations possibe using Mongo shell aggregation? I tried to get the sum of two fields using aggregation with following query. db.students.aggregate([ { $project: { examTotal: { $add: [ "$final", "$midterm" ] } } }, { $out: "students" } ]) But with this query its replacing the

Remove a specific id from all the collections in single query mongodb

吃可爱长大的小学妹 提交于 2019-12-13 21:03:59
问题 I have Reviews collection { "_id" : ObjectId("5ac47af5e935d927a03518ac"), "venue" : ObjectId("5abc9436b7c99332f0a68136"), "content" : "gfhfghfghfghf", } I have Event collection { "_id" : ObjectId("5abce7208b9efa5a6b8e739b"), "venue" : ObjectId("5abc9436b7c99332f0a68136"), "description" : "22222222222222222222222222222222222222", } I have Venues collection { "_id" : ObjectId("5abc9436b7c99332f0a68136"), "name" : "ASA College - Manhattan Campus", "addedBy" : ObjectId("5abc93a85d3914318cc8d3d7")

Why isn't my $sort Operator on dates function consistent in my query?

ε祈祈猫儿з 提交于 2019-12-13 20:34:08
问题 I am trying to write a query to sort out documents based on descending dates ...{sort: {paymentDate: -1 }} order. The first time the query runs, the query section {sort: {paymentDate: -1 }} seems get ignored! However when I refresh the page in the browser, the query section {sort: {paymentDate: -1 }} is applied, and the query displays in the correct sort order. I need to know how to correct this issue! Find below the contents of my document after I run the recipientsDetails.find().fetch();

How to multi update of a nested array in MondoDB?

感情迁移 提交于 2019-12-13 19:18:49
问题 I have documents in a MongoDB 'playground' collection following the below "schema" : { "_id": ObjectId("54423b40c92f9fffb486a6d4"), "ProjectFileId": 1, "SourceLanguageId": 2, "TargetSegments": [ { "LanguageId": 1, "Segment": "Something", "Colors": [ 1, 2, 3 ], "Heights": [ 1, 2, 3 ], "Widths": [ 1, 2, 3 ] }, { "LanguageId": 1, "Segment": "Something", "Colors": [ 1, 2, 3 ], "Heights": [ 1, 2, 3 ], "Widths": [ 1, 2, 3 ] } ] } And the following update query: db.playground.update({ $and: [ {

mongo PHP app error: Fatal error: Uncaught exception 'MongoException' with message ''.' not allowed in key

人盡茶涼 提交于 2019-12-13 19:14:10
问题 I have the following PHP array: array (size=9) 'script_desc' => string 'Test Script' (length=21) 'script_date' => string 'May 11 2016 15:40:48' (length=20) 'log_date' => string 'May 12 2016 09:17:58' (length=20) 'name' => string 'test name' (length=2) 'type' => string 'location_status' (length=15) 'status' => boolean false 'test.server.1' => array (size=1) 'packages' => array (size=2) 'package1' => array (size=4) 'package_name' => string 'package1' (length=10) 'current_version' => string

mongodb : find() query in a collection

妖精的绣舞 提交于 2019-12-13 19:11:08
问题 What I have : list of company names : [bmw, tata, ferrari,...] transmission: Manual or Automatic3. car color: Red or White etc model year: 2010 to 2014 Min Price & Max Price. --> Price range What i can do now : if i had only one object (ie. one company in companies) then i would do something like : query = {{transmission_type : transmission}, {color : car_color}, {year : model_year}, { $range: [ 0, "$PriceInINR", 25 ] } } db.companies.cars.find(query) But here first there are a lot of

How to search for text or expression in multiple fields

你说的曾经没有我的故事 提交于 2019-12-13 18:46:43
问题 db.movies.find({"original_title" : {$regex: input_data, $options:'i'}}, function (err, datares){ if (err || datares == false) { db.movies.find({"release_date" : {$regex: input_data + ".*", $options:'i'}}, function (err, datares){ if(err || datares == false){ db.movies.find({"cast" : {$regex: input_data, $options:'i'}}, function (err, datares){ if(err || datares == false){ db.movies.find({"writers" : {$regex: input_data, $options:'i'}}, function (err, datares){ if(err || datares == false){ db