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;








1















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










share|improve this question

















  • 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











  • @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












  • 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

















1















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










share|improve this question

















  • 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











  • @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












  • 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













1












1








1








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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











  • 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












  • 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











  • @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












  • 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







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












1 Answer
1






active

oldest

votes


















3














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






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    3














    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






    share|improve this answer



























      3














      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






      share|improve this answer

























        3












        3








        3







        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






        share|improve this answer













        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 13:37









        simagixsimagix

        1,0901 gold badge2 silver badges6 bronze badges




        1,0901 gold badge2 silver badges6 bronze badges


















            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.



















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현