mongodb-query

Retrieve Relevance Ordered Result from Text Query on MongoDB Collection using the C# Driver

天涯浪子 提交于 2019-12-07 15:29:25
I am attempting to text query a collection and retrieve the results in the text match order. The docs explain pretty well how to do this in the shell: db.articles.find( { status: "A", $text: { $search: "coffee cake" } }, { score: { $meta: "textScore" } } ).sort( { date: 1, score: { $meta: "textScore" } } ) but it requires the projection of the additional score field from the find into the sort. In C#, I have a function that looks like this: public IEnumerable<T> TextSearch<T>(MongoCollection<T> coll, string text) { var cursor = coll.Find(Query.Text(text)) .SetSortOrder(SortBy<T>.MetaTextScore(

How to filter based on nested array element in C# Mongodb strongly typed driver

≯℡__Kan透↙ 提交于 2019-12-07 14:32:14
问题 I am using the official C# MongoDb strongly typed driver version 2.7.0-beta001 to interact with MongoDB v 4.0-rc1 on Windows 10 machine. Consider the following classes: public class Library { [BsonId] [BsonRepresentation(BsonType.ObjectId)] public string Id { get; set; } public DateTime DateAdded { get; set; } public DateTime LastModified { get; set; } public string Title { get; set; } public Author Author { get; set; } public bool AllBooks { get; set; } } public class Author { [BsonId]

How to query BsonExtraElements in MongoDB via Linq

断了今生、忘了曾经 提交于 2019-12-07 14:01:19
问题 I used the mongodb [BsonExtraElements] feature to extend my class some dynamic data, but unfortunately I cannot create a query by mongodb C# driver. Here is my model class: public class MongoProductEntity { public MongoProductEntity() { AdditionalColumns = new BsonDocument { AllowDuplicateNames = false }; } [BsonExtraElements] public BsonDocument AdditionalColumns { get; set; } public string BrandName { get; set; } } Here is the query part: var productEntity = new MongoProductEntity () {

how to aggregate after populate with mongoose

十年热恋 提交于 2019-12-07 13:43:20
问题 I'm working with mongoose, and I have a problem in doing aggregate after populate. Belows are an example. There are two mongoose model schema, monster and collection. const monster = new Schema({ name: { type: String }, power: { type: Number }, armor: { type: Number }, }); const collection = new Schema({ _monster: { type: Schema.Types.ObjectId, ref: 'Monster' }, addedPower: { type: Number }, addedArmor: { type: Number }, }); As you see, field '_monster' is foreign key of schema 'collection'

Meteor: how do I return data from fields in a specific object?

前提是你 提交于 2019-12-07 12:33:30
This should be a fairly simple one. myobject has various properties, _id, name, createdBy, date etc In my find query I want to only return specific fields from within myObject. So for example, what would I need to do to modify the find query below so that only name was returned? myCollection.find({createdBy: someId}, {fields: {myObject: 1}}).fetch(); Currently this will return everything in myObject which it should do, I just want one field within myObject returned. chreyes Here is a way to do it within the query: myCollection.find({createdBy: someId}, {fields: {'myObject.name': 1}}).fetch();

Range support over time bucketed analytics

廉价感情. 提交于 2019-12-07 12:18:09
问题 Read this, and tried experimenting it. Below is my schema. SCHEMA: { "s" : "CB", "c" : "REQ_RCV", "e" : "sms_click", "st" : "i", "b" : "2", "a" : "1", "u" : "b1_h1_d1_m1_user_2", "c#" : "b1_h1_d1_m1_cr-2", "@" : ISODate("2016-10-01T06:03:00.000Z"), //Indexed "@h" : "16100106", //hourly bucket "@d" : "161001", //Indexed "@m" : "1610" } And below is the explain plan: > 2017-01-22T13:43:47.764+0530 I COMMAND [conn34] command test-analytics.template3 appName: "MongoDB Shell" command: aggregate {

Find first element in nested array that match conditions

那年仲夏 提交于 2019-12-07 11:36:45
问题 I have following documents: doc1: { 'array': [ {'field': 'ABC', 'enabled': 'false'}, {'field': 'BCD', 'enabled': 'true'}, {'field': 'DEF', 'enabled': 'false'}, {'field': 'XYZ', 'enabled': 'true'}, ] } doc2: { 'array': [ {'field': 'ABC', 'enabled': 'true'}, {'field': 'BCD', 'enabled': 'true'}, {'field': 'DEF', 'enabled': 'false'}, {'field': 'XYZ', 'enabled': 'true'}, ] } I'm performing search by particular field. I want to get all documents that have this field enabled, and there are no other

How to do nested $lookup search in MongoDB?

若如初见. 提交于 2019-12-07 11:13:17
问题 I have 3 collections: positions: +------------------+----------------------+-----------------------+ | position_id | company_id | position_name | +------------------+----------------------+-----------------------+ | 1 | 1 | position 1 | +------------------+----------------------+-----------------------+ | 2 | 2 | position 2 | +------------------+----------------------+-----------------------+ companies: +------------------+----------------------+-----------------------+ | company_id |

Mongo DB insert into a sub document if sub document value doesn't exist

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 11:06:50
问题 I'm very new to mongodb and i'm a little lost. I have mongo db collection that looks like this : ({ _id:id , createdAt: new Date(), name:name, friends : [{name:1,children:[{name:sarah,age:12}]}], dogs : [{}] }); I would like to be able to insert a new element in the friends array if the name doesnt exist and a children element to that new array. Pseudo code would be If Directory.find id.friends.name = true update and add a new children document {name:"sarah",age:5} else make a new friend

MongoDB Aggregate Time Series

淺唱寂寞╮ 提交于 2019-12-07 10:18:48
问题 I'm using MongoDB to store time series data using a similar structure to "The Document-Oriented Design" explained here: http://blog.mongodb.org/post/65517193370/schema-design-for-time-series-data-in-mongodb The objective is to query for the top 10 busiest minutes of the day on the whole system. Each document stores 1 hour of data using 60 sub-documents (1 for each minute). Each minute stores various metrics embedded in the "vals" field. The metric I care about is "orders". A sample document