lucdrb Active Member Licensed User Longtime User Mar 28, 2018 #1 Hi I would like to use the distinct command from Mongodb in B4J but I can't find How To: Syntax in mongoDb is Code: db.collection.distinct(field, query, options) It Finds the distinct values for a specified field across a single collection or view and returns the results in an array. Help would be welcome Thanks in advance Luc
Hi I would like to use the distinct command from Mongodb in B4J but I can't find How To: Syntax in mongoDb is Code: db.collection.distinct(field, query, options) It Finds the distinct values for a specified field across a single collection or view and returns the results in an array. Help would be welcome Thanks in advance Luc
Erel B4X founder Staff member Licensed User Longtime User Mar 29, 2018 #2 I will add it next week. Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Apr 3, 2018 #4 It is very simple to find distinct values with the aggregate method: Data: Code: Dim collection As MongoCollection = db.GetCollection("test") collection.Insert(Array(CreateMap("value": 100), CreateMap("value": 200), CreateMap("value": 200))) Find distinct values of value field: Code: For Each m As Map In collection.Aggregate(Array(CreateMap("$group": CreateMap("_id": "$value")))) Log(m.Get("_id")) Next Upvote 0
It is very simple to find distinct values with the aggregate method: Data: Code: Dim collection As MongoCollection = db.GetCollection("test") collection.Insert(Array(CreateMap("value": 100), CreateMap("value": 200), CreateMap("value": 200))) Find distinct values of value field: Code: For Each m As Map In collection.Aggregate(Array(CreateMap("$group": CreateMap("_id": "$value")))) Log(m.Get("_id")) Next
lucdrb Active Member Licensed User Longtime User Apr 3, 2018 #5 Thanks Erel, This week-end I've found that the distinct command exist as a database command. As I think that if it's possible to make it from the database side it would be better, I used it with the RunCommand (Command As Map) As Map Of the MongoDatabase from the JmongoDB library. But I'll be very gratefull to have the same RunCommand for all the collections methods (https://docs.mongodb.com/manual/reference/method/js-collection/). Annyway, thanks you for all that you've allready made. Luc Upvote 0
Thanks Erel, This week-end I've found that the distinct command exist as a database command. As I think that if it's possible to make it from the database side it would be better, I used it with the RunCommand (Command As Map) As Map Of the MongoDatabase from the JmongoDB library. But I'll be very gratefull to have the same RunCommand for all the collections methods (https://docs.mongodb.com/manual/reference/method/js-collection/). Annyway, thanks you for all that you've allready made. Luc
Erel B4X founder Staff member Licensed User Longtime User Apr 4, 2018 #6 lucdrb said: As I think that if it's possible to make it from the database side it would be better Click to expand... The aggregate commands are executed on the server, not on the client. Upvote 0
lucdrb said: As I think that if it's possible to make it from the database side it would be better Click to expand... The aggregate commands are executed on the server, not on the client.
lucdrb Active Member Licensed User Longtime User Apr 4, 2018 #7 The aggregate commands are executed on the server, not on the client. Click to expand... You're right my mistake. Upvote 0
The aggregate commands are executed on the server, not on the client. Click to expand... You're right my mistake.