Distinct in CosmosDB via MongoDB API

Multi tool use
Multi tool use












0















I am building a MERN-stack app that has a CosmosDB database on the backend with a collection with structure similar to the below:



{ 
"_id" : ObjectId("5c22dd1d58e77e47ac6361ae"),
"company" : "Company 1",
"feature" : "Feature 1",
"date" : "2018-10-04"
}
{
"_id" : ObjectId("5c22ddcb58e77e47ac6361af"),
"company" : "Company 2",
"feature" : "Feature 1",
"date" : "2018-03-12"
}
{
"_id" : ObjectId("5c22ddfc58e77e47ac6361b0"),
"company" : "Company 2",
"feature" : "Feature 2",
"date" : "2018-11-13"
}


I need the API to serve a list of all the "company"s that have listed features. Normally, if this were a SQL database it would be SELECT DISTINCT company FROM features, but when I try to execute the query db.getCollection("features").distinct("company"), I get:



[js] Error: distinct failed: {
"_t" : "OKMongoResponse",
"ok" : 0,
"code" : 115,
"errmsg" : "Command is not supported",
"$err" : "Command is not supported"
}


In doing some research, it appears that CosmosDB was originally shipped without the ability to do a DISTINCT, but was added earlier this year. Is there a reason this is failing, or is there a different way I can get the results of the query, or do I need to pull all the data and then de-dupe it in my program logic?










share|improve this question























  • Not all MongoDB commands are implemented with Cosmos DB's MongoDB PI. According to documentation, distinct is implemented in the aggregation pipeline - have you tried using that?

    – David Makogon
    Dec 31 '18 at 2:26













  • @DavidMakogon Is there a special syntax for aggregation pipeline? I'm not sure how to leverage it...

    – JGrindal
    Dec 31 '18 at 6:25
















0















I am building a MERN-stack app that has a CosmosDB database on the backend with a collection with structure similar to the below:



{ 
"_id" : ObjectId("5c22dd1d58e77e47ac6361ae"),
"company" : "Company 1",
"feature" : "Feature 1",
"date" : "2018-10-04"
}
{
"_id" : ObjectId("5c22ddcb58e77e47ac6361af"),
"company" : "Company 2",
"feature" : "Feature 1",
"date" : "2018-03-12"
}
{
"_id" : ObjectId("5c22ddfc58e77e47ac6361b0"),
"company" : "Company 2",
"feature" : "Feature 2",
"date" : "2018-11-13"
}


I need the API to serve a list of all the "company"s that have listed features. Normally, if this were a SQL database it would be SELECT DISTINCT company FROM features, but when I try to execute the query db.getCollection("features").distinct("company"), I get:



[js] Error: distinct failed: {
"_t" : "OKMongoResponse",
"ok" : 0,
"code" : 115,
"errmsg" : "Command is not supported",
"$err" : "Command is not supported"
}


In doing some research, it appears that CosmosDB was originally shipped without the ability to do a DISTINCT, but was added earlier this year. Is there a reason this is failing, or is there a different way I can get the results of the query, or do I need to pull all the data and then de-dupe it in my program logic?










share|improve this question























  • Not all MongoDB commands are implemented with Cosmos DB's MongoDB PI. According to documentation, distinct is implemented in the aggregation pipeline - have you tried using that?

    – David Makogon
    Dec 31 '18 at 2:26













  • @DavidMakogon Is there a special syntax for aggregation pipeline? I'm not sure how to leverage it...

    – JGrindal
    Dec 31 '18 at 6:25














0












0








0








I am building a MERN-stack app that has a CosmosDB database on the backend with a collection with structure similar to the below:



{ 
"_id" : ObjectId("5c22dd1d58e77e47ac6361ae"),
"company" : "Company 1",
"feature" : "Feature 1",
"date" : "2018-10-04"
}
{
"_id" : ObjectId("5c22ddcb58e77e47ac6361af"),
"company" : "Company 2",
"feature" : "Feature 1",
"date" : "2018-03-12"
}
{
"_id" : ObjectId("5c22ddfc58e77e47ac6361b0"),
"company" : "Company 2",
"feature" : "Feature 2",
"date" : "2018-11-13"
}


I need the API to serve a list of all the "company"s that have listed features. Normally, if this were a SQL database it would be SELECT DISTINCT company FROM features, but when I try to execute the query db.getCollection("features").distinct("company"), I get:



[js] Error: distinct failed: {
"_t" : "OKMongoResponse",
"ok" : 0,
"code" : 115,
"errmsg" : "Command is not supported",
"$err" : "Command is not supported"
}


In doing some research, it appears that CosmosDB was originally shipped without the ability to do a DISTINCT, but was added earlier this year. Is there a reason this is failing, or is there a different way I can get the results of the query, or do I need to pull all the data and then de-dupe it in my program logic?










share|improve this question














I am building a MERN-stack app that has a CosmosDB database on the backend with a collection with structure similar to the below:



{ 
"_id" : ObjectId("5c22dd1d58e77e47ac6361ae"),
"company" : "Company 1",
"feature" : "Feature 1",
"date" : "2018-10-04"
}
{
"_id" : ObjectId("5c22ddcb58e77e47ac6361af"),
"company" : "Company 2",
"feature" : "Feature 1",
"date" : "2018-03-12"
}
{
"_id" : ObjectId("5c22ddfc58e77e47ac6361b0"),
"company" : "Company 2",
"feature" : "Feature 2",
"date" : "2018-11-13"
}


I need the API to serve a list of all the "company"s that have listed features. Normally, if this were a SQL database it would be SELECT DISTINCT company FROM features, but when I try to execute the query db.getCollection("features").distinct("company"), I get:



[js] Error: distinct failed: {
"_t" : "OKMongoResponse",
"ok" : 0,
"code" : 115,
"errmsg" : "Command is not supported",
"$err" : "Command is not supported"
}


In doing some research, it appears that CosmosDB was originally shipped without the ability to do a DISTINCT, but was added earlier this year. Is there a reason this is failing, or is there a different way I can get the results of the query, or do I need to pull all the data and then de-dupe it in my program logic?







azure azure-cosmosdb azure-cosmosdb-mongoapi






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 30 '18 at 20:35









JGrindalJGrindal

392317




392317













  • Not all MongoDB commands are implemented with Cosmos DB's MongoDB PI. According to documentation, distinct is implemented in the aggregation pipeline - have you tried using that?

    – David Makogon
    Dec 31 '18 at 2:26













  • @DavidMakogon Is there a special syntax for aggregation pipeline? I'm not sure how to leverage it...

    – JGrindal
    Dec 31 '18 at 6:25



















  • Not all MongoDB commands are implemented with Cosmos DB's MongoDB PI. According to documentation, distinct is implemented in the aggregation pipeline - have you tried using that?

    – David Makogon
    Dec 31 '18 at 2:26













  • @DavidMakogon Is there a special syntax for aggregation pipeline? I'm not sure how to leverage it...

    – JGrindal
    Dec 31 '18 at 6:25

















Not all MongoDB commands are implemented with Cosmos DB's MongoDB PI. According to documentation, distinct is implemented in the aggregation pipeline - have you tried using that?

– David Makogon
Dec 31 '18 at 2:26







Not all MongoDB commands are implemented with Cosmos DB's MongoDB PI. According to documentation, distinct is implemented in the aggregation pipeline - have you tried using that?

– David Makogon
Dec 31 '18 at 2:26















@DavidMakogon Is there a special syntax for aggregation pipeline? I'm not sure how to leverage it...

– JGrindal
Dec 31 '18 at 6:25





@DavidMakogon Is there a special syntax for aggregation pipeline? I'm not sure how to leverage it...

– JGrindal
Dec 31 '18 at 6:25












1 Answer
1






active

oldest

votes


















0














According to Use Azure Cosmos DB's API for MongoDB support for MongoDB features and syntax > Aggregation pipeline, distinct, which is part of the aggregation pipeline, is only supported in public preview.



See Azure #CosmosDB extends support for MongoDB aggregation pipeline, unique indexes, and more on how to onboard to the public preview.



Hope it helps!






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%2f53981224%2fdistinct-in-cosmosdb-via-mongodb-api%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









    0














    According to Use Azure Cosmos DB's API for MongoDB support for MongoDB features and syntax > Aggregation pipeline, distinct, which is part of the aggregation pipeline, is only supported in public preview.



    See Azure #CosmosDB extends support for MongoDB aggregation pipeline, unique indexes, and more on how to onboard to the public preview.



    Hope it helps!






    share|improve this answer




























      0














      According to Use Azure Cosmos DB's API for MongoDB support for MongoDB features and syntax > Aggregation pipeline, distinct, which is part of the aggregation pipeline, is only supported in public preview.



      See Azure #CosmosDB extends support for MongoDB aggregation pipeline, unique indexes, and more on how to onboard to the public preview.



      Hope it helps!






      share|improve this answer


























        0












        0








        0







        According to Use Azure Cosmos DB's API for MongoDB support for MongoDB features and syntax > Aggregation pipeline, distinct, which is part of the aggregation pipeline, is only supported in public preview.



        See Azure #CosmosDB extends support for MongoDB aggregation pipeline, unique indexes, and more on how to onboard to the public preview.



        Hope it helps!






        share|improve this answer













        According to Use Azure Cosmos DB's API for MongoDB support for MongoDB features and syntax > Aggregation pipeline, distinct, which is part of the aggregation pipeline, is only supported in public preview.



        See Azure #CosmosDB extends support for MongoDB aggregation pipeline, unique indexes, and more on how to onboard to the public preview.



        Hope it helps!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 31 '18 at 8:20









        Itay PodhajcerItay Podhajcer

        1,9891412




        1,9891412






























            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%2f53981224%2fdistinct-in-cosmosdb-via-mongodb-api%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







            hi,BZPAbxFeZzqSuh1Z,9UiQRcG,EBxjE811pmv3p,Jd 4lVb,4CR tXV,9z6B,Ej9L
            20 Q,70ZcnQUKGvGq8GRDMi

            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas