mongodb-query

Text search query for text “other” always returns no results?

允我心安 提交于 2019-12-20 04:15:04
问题 My data looks like this: [{"id" : 1, "question" : "Other specified dermatomycoses", ... }, {"id" : 6, "question" : "Other specified disorders of joint, site unspecified", ... }] plus a few other records. If I run db.questions.find({$text:{$search:'other'}}).count() I always get 0. But if I run db.questions.find({$text:{$search:'specified'}}).count() I get the 2 that I expect. Most searches work properly, but not the word "other". Any ideas? 回答1: This is a commonplace occurance in "text search

How to return a nested document in an array

此生再无相见时 提交于 2019-12-20 04:14:01
问题 I have documents with a schema such as follows: { "user_id": 123, "services":[ {"name": "test", "data": ... }, {"name": "test1", "data": ... }, {"name": "test2", "data": ... } ] } I'm trying to get a service by name for a specific user_id returned as follows: {"name": "test2", "data": ... } I'm having difficulty wrapping my head around how to do this and seems an aggregation shouldn't be needed for something as simple as this but maybe I'm wrong. I'm sure a projection would work in a find_one

$expr arrayElementAt not working in aggregation for embedded document

守給你的承諾、 提交于 2019-12-20 03:56:09
问题 I am doing mongo db aggregation like $cursor = $this->collection->aggregate( array( array( '$project' => array( 'FullName' => array('$concat' => array('$first_name', ' ', '$middle_name', ' ', '$last_name')), 'FirstMiddle' => array('$concat' => array('$first_name', ' ', '$middle_name')), 'FirstLast' => array('$concat' => array('$first_name', ' ', '$last_name')), 'FirstName' => array('$concat' => array('$first_name')), 'MiddleName' => array('$concat' => array('$middle_name')), 'LastName' =>

Reading of DBname.system.indexes failed on Atlas cluster by mongobee after getting connected

匆匆过客 提交于 2019-12-20 03:32:40
问题 I have a Jhipster Spring boot project. Recently I shifted from mlabs standalone sandboxes to Atlas cluster sandbox M0 Free tier replica set. It even worked and I had made some database operations on it. But now for some reason then there is a read permission error Error creating bean with name 'mongobee' defined in class path resource [DatabaseConfiguration.class]: Invocation of init method failed; nested exception is com.mongodb.MongoQueryException: Query failed with error code 8000 and

Analog for group concat in sql

这一生的挚爱 提交于 2019-12-20 03:28:06
问题 In an aggregation process I've got this data: { "_id" : "billing/DefaultController/actionIndex", "min_time" : 0.033, "max_time" : 5.25, "exec_time" : 555.490999999997, "qt" : 9059, "count" : 2, "date" : [ ISODate("2014-02-10T00:00:00.000Z"), ISODate("2014-02-11T00:00:00.000Z") ] }, How to change my query: db.page_speed_reduced.aggregate([ {$group: { _id: "$value.route", min_time: {$min: "$value.min_time"}, max_time: {$max: "$value.max_time"}, exec_time: {$sum: "$value.exec_time"}, qt: {$sum:

Find sum of fields inside array in MongoDB

梦想的初衷 提交于 2019-12-20 03:18:01
问题 I have a data as follows: > db.PQRCorp.find().pretty() { "_id" : 0, "name" : "Ancy", "results" : [ { "evaluation" : "term1", "score" : 1.463179736705023 }, { "evaluation" : "term2", "score" : 11.78273309957772 }, { "evaluation" : "term3", "score" : 6.676176060654615 } ] } { "_id" : 1, "name" : "Mark", "results" : [ { "evaluation" : "term1", "score" : 5.89772766299929 }, { "evaluation" : "term2", "score" : 12.7726680028769 }, { "evaluation" : "term3", "score" : 2.78092882672992 } ] } { "_id" :

Mongo groupby month using UNIX millisecond time

房东的猫 提交于 2019-12-20 03:16:08
问题 I have a Mongo collection that looks as follows: [{ id: 1, timestamp: 1534488870841, type: 'deposit' }, { id: 1, timestamp: 1534488915119, type: 'deposit' }] How can I make a query to list all deposit transactions, grouped by the month. The month must be calculated using the timestamp attribute (UNIX millisecond). I can get the deposit's as follows but I am unsure on how to group: db.getCollection('transactions').find( {"type":"deposit"}); Edit : Mongo version 3.4 回答1: You can try below

How to ignore nulls while unmarshalling a MongoDB document?

馋奶兔 提交于 2019-12-20 02:56:38
问题 I would like to know if there's any approach that would allow me to ignore null types while unmarshalling a MongoDB document into a Go struct. Right now I have some auto-generate Go structs, something like this: type User struct { Name string `bson:"name"` Email string `bson:"email"` } Changing the types declared in this struct is not an option, and here's the problem; in a MongoDB database, which I do not have total control, some of the documents have been inserted with null values were

Mongodb multi nested array search

半腔热情 提交于 2019-12-20 02:42:28
问题 My aim is to search records of data userid 1 Below is my data { "_id" : 2, "name" : "test", "data" :[{"_id" : "1","file" : "nic", "userid" : [1,2 ]}, {"_id" : "2","file" : "nic1","userid" : [1 ] }, {"_id" : 3,"file" : "nick2","userid" : [1,2 ]} ]}, { "_id" : 3, "name" : "test", "data" : [{"_id" : "1","file" : "nic","userid" : [1,2 ] }, {"_id" : "2","file" : "nic1", "userid" : [3,2 ] } ]} out put should be { "_id" : 2, "name" : "test", "data" :[{"_id" : "1","file" : "nic", "userid" : [1,2 ]},

$elemMatch query in MongoDB

萝らか妹 提交于 2019-12-20 02:42:27
问题 I have a collection 'name' with 2 documents of the structure : doc 1: { a: 1 b : [{name:"AAA",age:10}, {name:"BBB",age:12}, {name:"CCC",age:13}] } doc 2 : { a: 2 b : [{name:"DDD",age:14}, {name:"EEE",age:15}, {name:"FFF",age:16}] } Since I am new to MongoDB, I am trying to find the difference of using the $elemMatch operator and not using it. Basically I am trying to query and find the first doc ( doc 1) with name AAA and age 10. So using the $elemMatch, my query looks like this : db.name