querying

How do I find an object whose properties foo or bar equal a query value?

99封情书 提交于 2019-12-08 15:04:13
问题 I searched google and looked at the docs, but I found no example of this. I have this object with embedded children: { teacher: "Balthazar", students: [ { name: 'Wilfred', sibling: 'Cordelia' }, { name: 'Mortimer', sibling: 'Arthur' }, { name: 'Cordelia', sibling: 'Wilfred' }, { name: 'Arthur' sibling: 'Mortimer' }, ] } I want to find Balthazar 's students whose name or sibling is in ['Wilfred', 'Cordelia', 'foo'] . I got it to work this way: criteria_a = balthazar.students.in(name: ['Wilfred

How to query with joins using sql alchemy?

一世执手 提交于 2019-12-08 10:32:09
问题 I am trying to use SqlAlchemy with mysql as backend.The following are my table schema (defined for ORM using SQLAlchemy): class ListItem(Base): """""" __tablename__ = "listitem" ListItemID = Column(Integer, primary_key=True) ListItemTypeID = Column(Integer, ForeignKey("ListItemType.ListItemTypeID")) ModelID = Column(Integer, ForeignKey("Model.ModelID")) RefCode = Column(String(25)) def __init__(self, ListItemTypeID, ModelID, RefCode): self.ListItemTypeID= ListItemTypeID self.ModelID= ModelID

MongoDB finding a speciffic document?

旧城冷巷雨未停 提交于 2019-12-08 03:17:25
问题 I'm struggling to find a specific document, as most tutorials are outdated, and my MongoDB version (the latest) does not have BasicDBObject. I'm using BSON, here is my attempt, public Document getPlayer(UUID uuid) { Document toFind = new Document("id", uuid); MongoCursor<Document> c = players.find(toFind).iterator(); while (c.hasNext()) { if (toFind.equals(c)) { return c; } } return null; } I'm fully aware this is wrong, but I just do not know how to find any information on MongoDB. 回答1: Look

MongoDB finding a speciffic document?

二次信任 提交于 2019-12-06 16:43:23
I'm struggling to find a specific document, as most tutorials are outdated, and my MongoDB version (the latest) does not have BasicDBObject. I'm using BSON, here is my attempt, public Document getPlayer(UUID uuid) { Document toFind = new Document("id", uuid); MongoCursor<Document> c = players.find(toFind).iterator(); while (c.hasNext()) { if (toFind.equals(c)) { return c; } } return null; } I'm fully aware this is wrong, but I just do not know how to find any information on MongoDB. Look at http://mongodb.github.io/mongo-java-driver/3.9/javadoc/index.html?overview-summary.html For normal

Querying JSON with JSONPath or SelectTokens? With JSON.NET in C#

人走茶凉 提交于 2019-12-06 08:46:33
问题 I am trying to use the Newtonsoft.Json.Net in c#. The following is part of JSON file that I need to retrieve data out of: { "video":{ "local_recording_device":{ "codecs":null }, "preferred_string":"___PREFERRED___", "streams":{ "99176901":{ "id":"99176901", "name":"PTZ Camera", "site":"someone", "email":"someone@awebsite.com", "codec":"VP8 HD1 (720p)", "local":true, "screen":false, "fit_to_window":true, "stay_on_top":false, "layout":0, "native_width":1280, "native_height":720, "window_width"

mongodb php getting fields unique values

只谈情不闲聊 提交于 2019-12-06 07:24:07
问题 I'm trying to get a list of unique values from the 'type' field from my mongodb collection. Example documents below: { "_id" : ..., "type" : "report", "tasks" : ... } { "_id" : ..., "type" : "research", "tasks" : ... } { "_id" : ..., "type" : "memo", "tasks" : ... } { "_id" : ..., "type" : "memo", "tasks" : ... } { "_id" : ..., "type" : "report", "tasks" : ... } { "_id" : ..., "type" : "report", "tasks" : ... } I'm looking for, ordered by frequency, the unique types that are in the type field

Rails order by count based on values of column

柔情痞子 提交于 2019-12-05 19:18:35
Rails 5.1.2 I have a two models Student and Award this way: class Student < ApplicationRecord has_many :awards end class Award < Application Record belongs_to :students # Categories scope :attendance, -> { where(category: 0) } #...(other award categories) scope :talent, -> { where(category: 8) } # Ranks # Gold scope :rank_1, -> { where(rank: 1) } # Silver scope :rank_2, -> { where(rank: 2) } # Bronze scope :rank_3, -> { where(rank: 3) } end Award has these columns: rank and category . Now, I want to get the top student for a given category. The criteria for this is, order by count of "gold"

How to make a query in this nested document structure (MongoDB)?

ぃ、小莉子 提交于 2019-12-05 11:59:32
(Sorry if it's a trivial question.) I have documents that looks like this (Python syntax): { '_id': SomeObjectId, 'features': [ {'id': 'featureX' , 'value': 6}, {'id': 'featureY', 'value': 45} ] } With this structure it's easy to find all documents that contains 'featureX' in the list of features. But I'm also interested in retrieving the value associated in the sub-document. I think in Python if I get the document with a query like this: db.articles.find({'features.id': 'featureX'}) then I would need to iterate over the array 'features' to find out the correct 'value'. Is there an other kind

MongoDB: how to find documents ignoring case sensitive, accents and percent like logic (%)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 01:16:18
问题 I would like to make a search on a collection in my mongodb database. In my collection, I have documents with the field "name" can be values like: [i] "Palácio Guanabara", "Palácio da Cidade", "Festa Palácio", etc. When a user types a search like "pala" or "palá" or "Pala" or "PalÁ", all those itens in [i] must build the result set. I found that in MongoDB I could use regex in searches, like: { "name": { $regex: new Regex(".*pala.*", "i") } } Ok, this approach is case insensitive and use the

Querying JSON with JSONPath or SelectTokens? With JSON.NET in C#

泪湿孤枕 提交于 2019-12-04 12:55:53
I am trying to use the Newtonsoft.Json.Net in c#. The following is part of JSON file that I need to retrieve data out of: { "video":{ "local_recording_device":{ "codecs":null }, "preferred_string":"___PREFERRED___", "streams":{ "99176901":{ "id":"99176901", "name":"PTZ Camera", "site":"someone", "email":"someone@awebsite.com", "codec":"VP8 HD1 (720p)", "local":true, "screen":false, "fit_to_window":true, "stay_on_top":false, "layout":0, "native_width":1280, "native_height":720, "window_width":456, "window_height":254, "preferred":false, "local_recording":false, "device_id":"MJPEG Camera",