nosql-aggregation

Mongodb Schema for Posts and Shares

痴心易碎 提交于 2019-12-12 04:54:28
问题 I am new to mongodb NoSQL concept and stuck at point where I am unable to take a decision for modelling the schema that could best serve my purpose. I need to design schema in such a way that I have my end result as Posts and Shares sorted by time . For this I considered two options: Option 1: Different Collection for Posts and Share as: Schema for Post collection : var postSchema = mongoose.Schema({ postText: String, postedBy: String, privacy: Number, updatedOn: { type: Date, default: Date

how to store & update matching values based on $OR operator, in mongodb?

走远了吗. 提交于 2019-12-11 17:18:36
问题 My collections contain nested document and I'm trying to get "Text" present in any of the nested fields such as: var rerun = { $or: [ {"code_exception.java_40.code.Text": { $exists : true, $ne : "" } },//13816 {"code_exception.java_15.code.Text":{ $exists : true, $ne : ""} },//13485 {"code_exception.java_10.code.Text":{ $exists : true, $ne : ""} },//12994 {"code_exception.java_2.code.Text": { $exists : true, $ne : ""} },//13294 {"code_exception.java_4.code.Text": { $exists : true, $ne : ""} }

How do you sort results of a _View_ by value in the in Couchbase?

匆匆过客 提交于 2019-12-06 04:06:06
问题 So from what I understand in Couchbase is that one can sort keys* by using descending=true but in my case I want to sort by values instead. Consider the Twitter data in json format, my question is What it the most popular user mentioned? Each tweet has the structure of: { "text": "", "entities" : { "hashtags" : [ ... ], "user_mentions" : [ ...], "urls" : [ ... ] } So having used MongoDB before I reused the Map function and modified it slightly to be usable in Couchbase as follows: function

Multiple group-by in Elasticsearch

本小妞迷上赌 提交于 2019-12-03 09:03:03
问题 I need to aggregate (group-by) using 3 fields in ES. Can I do that in 1 query or that I need to use a facet + iterate for each column? Thank you 回答1: You can do it by 2 ways : 1) using multiple fields in a single facet result : example for single fields facet : curl -X GET "http://localhost:9200/sales/order/_search?pretty=true" -d '{ "query": { "query_string": { "query": "shohi*", "fields": [ "billing_name" ] } }, "facets": { "facet_result": { "terms": { "fields": [ "status" ], "order": "term

Multiple group-by in Elasticsearch

我是研究僧i 提交于 2019-12-02 23:14:38
I need to aggregate (group-by) using 3 fields in ES. Can I do that in 1 query or that I need to use a facet + iterate for each column? Thank you Suhel Meman You can do it by 2 ways : 1) using multiple fields in a single facet result : example for single fields facet : curl -X GET "http://localhost:9200/sales/order/_search?pretty=true" -d '{ "query": { "query_string": { "query": "shohi*", "fields": [ "billing_name" ] } }, "facets": { "facet_result": { "terms": { "fields": [ "status" ], "order": "term", "size": 15 } } } }' example for multiple field in a single facet result : curl -X GET "http:/

Perform Aggregation/Set intersection on MongoDB

三世轮回 提交于 2019-12-02 16:54:27
问题 I have a query, consider the following example as a intermediate data after performing some aggregation on a sample dataset; fileid field contains the id of a file, and the user array containing array of users, who made some changes to the respective file { “_id” : { “fileid” : 12 }, “_user” : [ “a”,”b”,”c”,”d” ] } { “_id” : { “fileid” : 13 }, “_user” : [ “f”,”e”,”a”,”b” ] } { “_id” : { “fileid” : 14 }, “_user” : [ “g”,”h”,”m”,”n” ] } { “_id” : { “fileid” : 15 }, “_user” : [ “o”,”r”,”s”,”v” ]

Perform Aggregation/Set intersection on MongoDB

眉间皱痕 提交于 2019-12-02 10:26:47
I have a query, consider the following example as a intermediate data after performing some aggregation on a sample dataset; fileid field contains the id of a file, and the user array containing array of users, who made some changes to the respective file { “_id” : { “fileid” : 12 }, “_user” : [ “a”,”b”,”c”,”d” ] } { “_id” : { “fileid” : 13 }, “_user” : [ “f”,”e”,”a”,”b” ] } { “_id” : { “fileid” : 14 }, “_user” : [ “g”,”h”,”m”,”n” ] } { “_id” : { “fileid” : 15 }, “_user” : [ “o”,”r”,”s”,”v” ] } { “_id” : { “fileid” : 16 }, “_user” : [ “x”,”y”,”z”,”a” ] } { “_id” : { “fileid” : 17 }, “_user” :

MongoDB Count() vs. Aggregation

ⅰ亾dé卋堺 提交于 2019-12-02 06:14:39
问题 I've used aggregation in mongo a lot, I know performance benefits on the grouped counts and etc. But, do mongo have any difference in performance on those two ways to count all documents in a collection?: collection.aggregate([ { $match: {} },{ $group: { _id: null, count: {$sum: 1} } }]); and collection.find({}).count() Update : Second case: Let's say we have this sample data: {_id: 1, type: 'one', value: true} {_id: 2, type: 'two', value: false} {_id: 4, type: 'five', value: false} With

MongoDB Count() vs. Aggregation

半城伤御伤魂 提交于 2019-12-02 00:49:00
I've used aggregation in mongo a lot, I know performance benefits on the grouped counts and etc. But, do mongo have any difference in performance on those two ways to count all documents in a collection?: collection.aggregate([ { $match: {} },{ $group: { _id: null, count: {$sum: 1} } }]); and collection.find({}).count() Update : Second case: Let's say we have this sample data: {_id: 1, type: 'one', value: true} {_id: 2, type: 'two', value: false} {_id: 4, type: 'five', value: false} With aggregate() : var _ids = ['id1', 'id2', 'id3']; var counted = Collections.mail.aggregate([ { '$match': {

MAX(), DISTINCT and group by in Cassandra

拈花ヽ惹草 提交于 2019-11-27 08:39:18
I am trying to remodel a SQL database Cassandra such that, I can find the Cassandra equivalent for the SQL queries. I use CQL 3 and Cassandra v1.2. I modeled the db design in cassandra so that it supports the order by clauses and denormalized tables to support the join operation. However I am at sea when it comes to DISTINCT, SUM() and GROUPBY equvalents SELECT a1,MAX(b1) FROM demo1 group by a1. SELECT DISTINCT (a2) FROM demo2 where b2='sea' SELECT sum(a3), sum(b3) from demo3 where c3='water' and d3='ocean' This is like a showstopper to my work for past couple of days. Is there a way in