mongodb-query

How to group data using mongo-template

只愿长相守 提交于 2021-01-28 11:27:17
问题 I have to filter data based on a criteria and set a field isObtained true or false. Then I am trying to group the data based on field grade . This is my data: { "school": "xyz", "studentName": "John Doe", "grade": "first", "Hobbies": [ "Painting", "Singing" ], "language": [ "English" ], "sport": "Badminton", "totalStudyHours": 85 }, { "school": xyz, "studentName": "Jane Doe", "grade": "third", "Hobbies": [ "Painting", ], "language": [ "Spanish" ], "sport": "Karate", "totalStudyHours": 65 }, {

Sort documents by value in the last element of an array that matches filter. Mongodb

假装没事ソ 提交于 2021-01-28 11:24:17
问题 I have a collection of evaluationGroups with the following documents structure: { "_id" : ObjectId("60073749694fd4d81e4d677d"), "AlertSettingId" : ObjectId("5ffddaaa0b1d2c30b191599a"), "CurrentStatus" : "success", "Evaluations" : [ { "EvaluatedAt" : ISODate("2021-01-19T19:47:18.850Z"), "ReferenceValue" : 1.0, "Status" : "success" }, { "EvaluatedAt" : ISODate("2021-01-19T19:52:16.423Z"), "ReferenceValue" : 1.0, "Status" : "triggered" }, { "EvaluatedAt" : ISODate("2021-01-19T21:47:16.400Z"),

$fitler nested array using $lte $gte

我只是一个虾纸丫 提交于 2021-01-28 11:06:34
问题 I am implementing a backend using Mongoose and MongoDB with "user" documents such as this: > db.users.find().pretty() { "_id" : ObjectId("5c46eb642c825626124b1e3c"), "username" : "admin", "searches" : [ ISODate("2019-01-30T14:52:07Z"), ISODate("2019-01-30T14:53:40Z"), ISODate("2019-01-30T14:54:48Z"), ISODate("2019-02-03T17:11:57Z"), ISODate("2019-02-04T06:40:00Z") ] } The searches field is an array logging the time when the user run some search functionality. I want to select a username and

How to use $query, $hint or $explain from Java

冷暖自知 提交于 2021-01-28 05:52:03
问题 I am using MongoDB 3.4 My methods are:- MongoDatabase db = mongo.getDatabase(mongoDBLogs); MongoIterable<String> allCollections = db.listCollectionNames(); str==FROM COLLECTION MongoCollection<Document> table = db.getCollection(str); MongoCursor<Document> cursor = table.find(queryForLogs).iterator(); The problem is in OLD version I can use the DB db = mongo.getDB(mongoDBLogs); Set<String> colls = db.getCollectionNames(); for (String s : colls) { DBCollection table = db.getCollection(s);

Spring-Mongo-Data Update only allows one positional argument?

淺唱寂寞╮ 提交于 2021-01-28 05:17:38
问题 I have a data model with the following structure: { _id: ObjectId(''), strs: [ { _id: ObjectId(''), nds: [ { _id: ObjectId(''), title: '' }, . . . ] }, . . . ] } Following query works perfectly fine in mongo shell: mongo.update({_id: ObjectId(''), 'strs._id': ObjectId(''), 'strs.nds._id': ObjectId('')}, {$set: {'strs.$.nds.$.title': 'new-title'}}) I am trying to do the same in Spring Boot, I have written the following lines of code: Criteria criteria = new Criteria(); criteria.addOperator

Country state city select in nodejs using mongodb

浪尽此生 提交于 2021-01-28 05:11:51
问题 I am making a node.js website where I want to implement dependent dropdown for selecting location. I have created two collections in mongoDB using 'countries' and 'states+cities' json files from this source: "https://github.com/dr5hn/countries-states-cities-database". This is the html inside a form: <div class="form-group"> <label for="">Country</label> <select name="country" class="form-control btn btn-light select-country" id="selectCountry"></select> </div> <div class="form-group"> <label

MongoDB converts number to string in scientific notation

半城伤御伤魂 提交于 2021-01-28 05:00:20
问题 I want to get full number as a String , but instead "1490650000000" it returns scientific notation "1.49065e+12" Here's how I try to convert it: {$substr: ["$myNumber", 0, -1]}; Any ideas how to prevent it? Note: I'm using v3.6 and can't upgrade to use $toString (thanks mlab). 回答1: If you have mongodb 4.0 then you can use $toLong aggregation db.collection.aggregate([ { "$project": { "myNumber": { "$toLong": "$myNumber" } } } ]) 回答2: You can try as below. db.collectionName.aggregate([ {

MongoDB: Find document given field values in an object with an unknown key

半城伤御伤魂 提交于 2021-01-28 04:32:41
问题 I'm making a database on theses/arguments. They are related to other arguments, which I've placed in an object with a dynamic key, which is completely random. { _id : "aeokejXMwGKvWzF5L", text : "test", relations : { cF6iKAkDJg5eQGsgb : { type : "interpretation", originId : "uFEjssN2RgcrgiTjh", ratings: [...] } } } Can I find this document if I only know what the value of type is? That is I want to do something like this: db.theses.find({relations['anything']: { type: "interpretation"}}})

Max and group by in Mongodb

情到浓时终转凉″ 提交于 2021-01-28 04:06:32
问题 First of all we are just migrating from SQL Server to Mongodb. I have a collection containing fields TFN, Impressions . I need to transform the sql query in mongo but got stuck at a moment. Scenario is I need to select a top 5 impressions from the collection which are group by on the basis of tfns Select Top 5 a.TFN, a.MaxImpression as MaxCount from ( Select TFN, Max(Impressions) MaxImpression from tblData Where TFN in (Select TFN From @tmpTFNList) and TrendDate between @StartDate AND

MongoDB find subdocument and sort the results

一世执手 提交于 2021-01-28 02:56:13
问题 I have a collection in MongoDB with a complex structure and subdocuments. The document have an structure like this: doc1 = { '_id': '12345678', 'url': "http//myurl/...", 'nlp':{ "status": "OK", "entities": { "0": { "type" : "Person", "relevance": "0.877245", "text" : "Neelie Kroes" }, "1": { "type": "Company", "relevance": "0.36242", "text": "ICANN" }, "2": { "type": "Company", "relevance": "0.265175", "text": "IANA" } } } } doc2 = { '_id': '987456321', 'url': "http//myurl2/...", 'nlp':{