mongodb-query

mongoDB : multi value field search ignoring null fields

与世无争的帅哥 提交于 2019-12-25 02:01:23
问题 I am trying to make a search on several field where some of them can be left blank. Given the following Json document in MongoDB (only three fields here, but N fields in reality, with N > 10) : { 'first_name' : 'value_X', 'last_name' : 'value_Y', 'mail_adress' : 'value_Z' } Then let's suppose a form where the user can enter the value of the first name, last name, mail address and phone number. If all the field are filled the query in MongoDB looks like : db.collection.find( { 'first_name' :

Convert Mongodb schema including nested Object

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 01:55:13
问题 Suppose a mongodb collection schema like this: { "_id" : ObjectId("5a5b2657a19692e18a3792ad"), "Toponym" : "Climate station Stavenhagen", "Lat" : 53.33333, "Lon" : "13.99999", "SensorMaker" : "Hitachi", "SensorClass" : "Thermometer", "Dimension" : "SoilTemperature_0.05mSensor1", "Gauge" : "degC" } And I would like to change the complete collection (~ 90k items) to this, to conform to minimal GeoJson: { "_id" : ObjectId("5a5b2657a19692e18a3792ad"), "Toponym" : "Climate station Stavenhagen",

Matching ObjectId to String for $graphLookup

北城以北 提交于 2019-12-25 01:45:11
问题 I'm trying to run a $graphLookup like demonstrated in print bellow: The objective is to, given a specific record (commented $match there), retrieve it's full "path" throught immediateAncestors property. As you can see, it's not happening. I introduced $convert here to deal with _id from collection as string , believing it could be possible to "match" with _id from immediateAncestors records list (which is a string ). So, I did run another test with different data (no ObjectId s involved): db

Making Date queries on MongoDB using JSON on SpringDataMongoDB

独自空忆成欢 提交于 2019-12-25 01:39:43
问题 I'm having some trouble making MongoDB Date queries using @Query annotation on SpringDataMongoDB on a project created using JHipster. Since JHipster was used to create the project most of the queries were created using Spring Data query builder mechanism and for more refined queries, instead of using Type-safe Query methods I decided to stick with JHipster's standard configuration and make personalized queries using @Query annotation that allows the creation of MongoDBJSON queries. However, I

Mongodb find a value inside the array

拜拜、爱过 提交于 2019-12-25 01:32:12
问题 If I have this schema... person = { emails : Array } The values are stored in emails array as mentioned below: emails : [{ a : "a@a.com" , b: "b@b.com" , c : "c@c.com" }] Now i tried the below mentioned queries , Person.findOne({emails : "a@a.com"}).exec(function(err,person){ }); Mongodb native query Person.native(function(err,collection){ collection.find( emails : { "$in" : "a@a.com"} , function(err , result){ //code }); }); EDITED QUESTION Now i tried using OR as below. Person.findOne({ "or

Finding two elements in an array of documents that appear in a given order

a 夏天 提交于 2019-12-25 00:59:05
问题 Let's assume I have the following document structure in database: { name: String, subDocs: [{ index: Number, value: Number }] } So that a typical document looks like: { name: 'Document 1', subDocs: [ { index: 0, value: 30 }, { index: 1, value: 40 }, { index: 2, value: 10 }, { index: 3, value: 20 }, { index: 4, value: 700 }, { index: 5, value: 40 } ] } Now, I would like to find all documents which contain subDocs with values A = 10 and B = 40 BUT the occurrence of the items in the array must

Positional $ working on different parts of the same document?

↘锁芯ラ 提交于 2019-12-25 00:36:25
问题 I have the following record: r = { "_children" : { "addressesR" : [ { "street" : "Bitton", "city" : "Perth", "id" : ObjectId("5317c149f45dfdb114deec41") }, { "id" : ObjectId("5317c149f45dfdb114deec42"), "street" : "Ivermey", "city" : "Perth", ], }, "_searchData" : { "addressesR" : [ { "street" : "BITTON", "city" : "PERTH", "id" : ObjectId("5317c149f45dfdb114deec41") }, { "id" : ObjectId("5317c149f45dfdb114deec42"), "street" : "IVERMEY", "city" : "PERTH", } ], }, } Just save it: db.p.save( r )

MongoDB aggregate group on inner child collection and get complete document with count

可紊 提交于 2019-12-24 23:59:54
问题 I have a User collection, which further have a 'UserSubscription' collection, which further have 'Subscription > Publication'. Mongo collection looks like this /* 1 */ { "_id" : 1, "UserSubscriptions" : [ { "_id" : 1, "Subscription" : { "_id" : 1, "Publication" : { "_id" : 1, "Code" : "1MM", }, }, { "_id" : 2, "Subscription" : { "_id" : 2, "Publication" : { "_id" : 2, "Code" : "2MM", }, }, { "_id" : 7, "Subscription" : { "_id" : 7, "Publication" : { "_id" : 1, "Code" : "1MM", }, } ] } /* 2 */

What's the most economical alternative to multiple positional identifiers in MongoDB?

…衆ロ難τιáo~ 提交于 2019-12-24 23:23:57
问题 I have a collection named authors with the following schema: authors: { _id, firstName, lastName, posts: [ post 1: {...}, post 2: {...}, post 3: { _id, title, content, tags: [ tag 1: {...}, tag 2: {...}, tag 3: { _id, name, description, }, ], }, ], } As can be seen, posts is an array of objects inside the authors collection. Each object inside this array, in turn, has tags , another array of objects. And each of these tags objects has three fields: _id , name , and description . I'm trying to

mongo c driver: how to query documents with “_id” in a list?

本小妞迷上赌 提交于 2019-12-24 22:17:01
问题 I have a db with huge amount of documents, and I only want to query documents with "_id" from a list. I searched online for a few hours, and did not find anything really working, so I post my question here. Thank you very much for any help! in MongoDB command line environment, it is very easy to achieve what I want. The query command, for example, is as follows: db.collection.find({"_id":{$in:[ObjectId("595320c208b0c52a8b37c151"), ObjectId("595320c208b0c52a8b37c152"), ObjectId(