Filter in golang mongodbMongoDB vs. CassandraNoSQL (MongoDB) vs Lucene (or Solr) as your databaseHow to query MongoDB with “like”?When to Redis? When to MongoDB?How do I drop a MongoDB database from the command line?elasticsearch v.s. MongoDB for filtering application“Large data” work flows using pandasin Golang, what is the difference between json encoding and marshallingHow to auto-increment id field of mongodb with golang mgo driver?swap function not working in golang
Is this Android phone Android 9.0 or Android 6.0?
Can a pizza stone be fixed after soap has been used to clean it?
Alternator dying so junk car?
Advice for paying off student loans and auto loans now that I have my first 'real' job
Manually select/unselect lines before forwarding to stdout
How Can I Process Untrusted Data Sources Securely?
What impact would a dragon the size of Asia have on the environment?
Why should I cook the flour first when making bechamel sauce?
FPGA CPU's, how to find the max speed?
Sending a photo of my bank account card to the future employer
Can a Resident Assistant Be Told to Ignore a Lawful Order?
What is the German word or phrase for "village returning to forest"?
Should I be able to keep my company purchased standing desk when I leave my job?
Did 007 exist before James Bond?
What happens when I team swap while I have Pokemon inside a gym?
Can you perfectly wrap a cube with this blocky shape?
How to delete certain lists from a nested list?
Is it OK to use personal email ID for faculty job applications or should we use (current) institute's ID
Do I need a 50/60Hz notch filter for battery powered devices?
How fast does a character need to move to be effectively invisible?
How do I query for system views in a SQL Server database?
Cauchy reals and Dedekind reals satisfy "the same mathematical theorems"
Unix chat server making communication between terminals possible
Is there a standard way of referencing line numbers in a draft?
Filter in golang mongodb
MongoDB vs. CassandraNoSQL (MongoDB) vs Lucene (or Solr) as your databaseHow to query MongoDB with “like”?When to Redis? When to MongoDB?How do I drop a MongoDB database from the command line?elasticsearch v.s. MongoDB for filtering application“Large data” work flows using pandasin Golang, what is the difference between json encoding and marshallingHow to auto-increment id field of mongodb with golang mgo driver?swap function not working in golang
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Currently I learn to create restful api with golang and mongodb. Actually I am beginner in both. I use mongodb-go-driver and I learn to use filter when we want to use find()
function. But I have some that I don't understand. What is the different between filter := bson.M"_id": "abcd"
and filter := bson.M"_id": "abcd"
? Thank you
mongodb go
add a comment |
Currently I learn to create restful api with golang and mongodb. Actually I am beginner in both. I use mongodb-go-driver and I learn to use filter when we want to use find()
function. But I have some that I don't understand. What is the different between filter := bson.M"_id": "abcd"
and filter := bson.M"_id": "abcd"
? Thank you
mongodb go
1
filter := bson.M"_id": "abcd"
doesn't compile, so I don't know what you're asking. Maybe you meanfilter := []bson.M"_id": "abcd"
? That's a slice, a slice of "filters", most often used when specifying stages of a MongoDB aggregation.
– icza
Mar 26 at 8:40
@RiefSapthana. I think you meantfilter := bson.D"_id": "abcd"
. Usebson.D
when order matters, for example, multiple fields in the query filter. Either onebson.D
orbson.M
as filters, mongo engine is intelligent enough to give you the same result.
– simagix
Mar 26 at 23:32
Thank you @simagix @icza, what is the double bracesbson.D
mean? Doesbson.M
havebson.M
form?
– RiefSapthana
Mar 27 at 4:41
I got example like thisfilter := bson.M"_id": id
and thisfilter := bson.D"name", "Ash"
so whybson.D
use double braces? What does it mean?
– RiefSapthana
Mar 27 at 4:47
add a comment |
Currently I learn to create restful api with golang and mongodb. Actually I am beginner in both. I use mongodb-go-driver and I learn to use filter when we want to use find()
function. But I have some that I don't understand. What is the different between filter := bson.M"_id": "abcd"
and filter := bson.M"_id": "abcd"
? Thank you
mongodb go
Currently I learn to create restful api with golang and mongodb. Actually I am beginner in both. I use mongodb-go-driver and I learn to use filter when we want to use find()
function. But I have some that I don't understand. What is the different between filter := bson.M"_id": "abcd"
and filter := bson.M"_id": "abcd"
? Thank you
mongodb go
mongodb go
asked Mar 26 at 8:04
RiefSapthanaRiefSapthana
3091 gold badge4 silver badges18 bronze badges
3091 gold badge4 silver badges18 bronze badges
1
filter := bson.M"_id": "abcd"
doesn't compile, so I don't know what you're asking. Maybe you meanfilter := []bson.M"_id": "abcd"
? That's a slice, a slice of "filters", most often used when specifying stages of a MongoDB aggregation.
– icza
Mar 26 at 8:40
@RiefSapthana. I think you meantfilter := bson.D"_id": "abcd"
. Usebson.D
when order matters, for example, multiple fields in the query filter. Either onebson.D
orbson.M
as filters, mongo engine is intelligent enough to give you the same result.
– simagix
Mar 26 at 23:32
Thank you @simagix @icza, what is the double bracesbson.D
mean? Doesbson.M
havebson.M
form?
– RiefSapthana
Mar 27 at 4:41
I got example like thisfilter := bson.M"_id": id
and thisfilter := bson.D"name", "Ash"
so whybson.D
use double braces? What does it mean?
– RiefSapthana
Mar 27 at 4:47
add a comment |
1
filter := bson.M"_id": "abcd"
doesn't compile, so I don't know what you're asking. Maybe you meanfilter := []bson.M"_id": "abcd"
? That's a slice, a slice of "filters", most often used when specifying stages of a MongoDB aggregation.
– icza
Mar 26 at 8:40
@RiefSapthana. I think you meantfilter := bson.D"_id": "abcd"
. Usebson.D
when order matters, for example, multiple fields in the query filter. Either onebson.D
orbson.M
as filters, mongo engine is intelligent enough to give you the same result.
– simagix
Mar 26 at 23:32
Thank you @simagix @icza, what is the double bracesbson.D
mean? Doesbson.M
havebson.M
form?
– RiefSapthana
Mar 27 at 4:41
I got example like thisfilter := bson.M"_id": id
and thisfilter := bson.D"name", "Ash"
so whybson.D
use double braces? What does it mean?
– RiefSapthana
Mar 27 at 4:47
1
1
filter := bson.M"_id": "abcd"
doesn't compile, so I don't know what you're asking. Maybe you mean filter := []bson.M"_id": "abcd"
? That's a slice, a slice of "filters", most often used when specifying stages of a MongoDB aggregation.– icza
Mar 26 at 8:40
filter := bson.M"_id": "abcd"
doesn't compile, so I don't know what you're asking. Maybe you mean filter := []bson.M"_id": "abcd"
? That's a slice, a slice of "filters", most often used when specifying stages of a MongoDB aggregation.– icza
Mar 26 at 8:40
@RiefSapthana. I think you meant
filter := bson.D"_id": "abcd"
. Use bson.D
when order matters, for example, multiple fields in the query filter. Either one bson.D
or bson.M
as filters, mongo engine is intelligent enough to give you the same result.– simagix
Mar 26 at 23:32
@RiefSapthana. I think you meant
filter := bson.D"_id": "abcd"
. Use bson.D
when order matters, for example, multiple fields in the query filter. Either one bson.D
or bson.M
as filters, mongo engine is intelligent enough to give you the same result.– simagix
Mar 26 at 23:32
Thank you @simagix @icza, what is the double braces
bson.D
mean? Does bson.M
have bson.M
form?– RiefSapthana
Mar 27 at 4:41
Thank you @simagix @icza, what is the double braces
bson.D
mean? Does bson.M
have bson.M
form?– RiefSapthana
Mar 27 at 4:41
I got example like this
filter := bson.M"_id": id
and this filter := bson.D"name", "Ash"
so why bson.D
use double braces
? What does it mean?– RiefSapthana
Mar 27 at 4:47
I got example like this
filter := bson.M"_id": id
and this filter := bson.D"name", "Ash"
so why bson.D
use double braces
? What does it mean?– RiefSapthana
Mar 27 at 4:47
add a comment |
1 Answer
1
active
oldest
votes
Refer to the source code, https://github.com/mongodb/mongo-go-driver/blob/master/bson/primitive/primitive.go
bson.D
, internally is primitive.D
, which is []primitive.E
, which is a struct
. bson.M
, internally is primitive.M
, which is map[string]interface
. You put in key/value in bson.M
but use document (struct) in bson.D
.
It is better to explain it using 2 parameters, e.g. search for a = 1 and b = 2
. You syntax will be: bson.M"a": 1, "b": 2
or bson.D"a": 1, "b": 2
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55352362%2ffilter-in-golang-mongodb%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Refer to the source code, https://github.com/mongodb/mongo-go-driver/blob/master/bson/primitive/primitive.go
bson.D
, internally is primitive.D
, which is []primitive.E
, which is a struct
. bson.M
, internally is primitive.M
, which is map[string]interface
. You put in key/value in bson.M
but use document (struct) in bson.D
.
It is better to explain it using 2 parameters, e.g. search for a = 1 and b = 2
. You syntax will be: bson.M"a": 1, "b": 2
or bson.D"a": 1, "b": 2
add a comment |
Refer to the source code, https://github.com/mongodb/mongo-go-driver/blob/master/bson/primitive/primitive.go
bson.D
, internally is primitive.D
, which is []primitive.E
, which is a struct
. bson.M
, internally is primitive.M
, which is map[string]interface
. You put in key/value in bson.M
but use document (struct) in bson.D
.
It is better to explain it using 2 parameters, e.g. search for a = 1 and b = 2
. You syntax will be: bson.M"a": 1, "b": 2
or bson.D"a": 1, "b": 2
add a comment |
Refer to the source code, https://github.com/mongodb/mongo-go-driver/blob/master/bson/primitive/primitive.go
bson.D
, internally is primitive.D
, which is []primitive.E
, which is a struct
. bson.M
, internally is primitive.M
, which is map[string]interface
. You put in key/value in bson.M
but use document (struct) in bson.D
.
It is better to explain it using 2 parameters, e.g. search for a = 1 and b = 2
. You syntax will be: bson.M"a": 1, "b": 2
or bson.D"a": 1, "b": 2
Refer to the source code, https://github.com/mongodb/mongo-go-driver/blob/master/bson/primitive/primitive.go
bson.D
, internally is primitive.D
, which is []primitive.E
, which is a struct
. bson.M
, internally is primitive.M
, which is map[string]interface
. You put in key/value in bson.M
but use document (struct) in bson.D
.
It is better to explain it using 2 parameters, e.g. search for a = 1 and b = 2
. You syntax will be: bson.M"a": 1, "b": 2
or bson.D"a": 1, "b": 2
answered Mar 27 at 13:37
simagixsimagix
1,0901 gold badge2 silver badges6 bronze badges
1,0901 gold badge2 silver badges6 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55352362%2ffilter-in-golang-mongodb%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
filter := bson.M"_id": "abcd"
doesn't compile, so I don't know what you're asking. Maybe you meanfilter := []bson.M"_id": "abcd"
? That's a slice, a slice of "filters", most often used when specifying stages of a MongoDB aggregation.– icza
Mar 26 at 8:40
@RiefSapthana. I think you meant
filter := bson.D"_id": "abcd"
. Usebson.D
when order matters, for example, multiple fields in the query filter. Either onebson.D
orbson.M
as filters, mongo engine is intelligent enough to give you the same result.– simagix
Mar 26 at 23:32
Thank you @simagix @icza, what is the double braces
bson.D
mean? Doesbson.M
havebson.M
form?– RiefSapthana
Mar 27 at 4:41
I got example like this
filter := bson.M"_id": id
and thisfilter := bson.D"name", "Ash"
so whybson.D
use double braces? What does it mean?
– RiefSapthana
Mar 27 at 4:47