Nodejs mongoose sub sub document searchHow can I update NodeJS and NPM to the next versions?How do I update/upsert a document in Mongoose?NodeJs, Mocha and MongooseBest way to perform a full text search in MongoDB and MongooseHow to create Schema using mongodb(mongoose schema)?How to popoulate recursive schema references Mongodb, Mongoose, Express?Mongoose populate with match condition for nested documentMongoDB/ Mongoose many to many relationship - user, project and roleHow to make mongoose schema property of type (another) schema requiredMongoose: Add validators on the fly on some parameters depending on queries

mini sub panel?

Whose birthyears are canonically established in the MCU?

Opposite party turned away from voting when ballot is all opposing party

Crime rates in a post-scarcity economy

Light Switch Neutrals: Bundle all together?

Wiper fluid only squirts out for a second - Hyundai Accent 2006

Expl3 and recent xparse on overleaf: No expl3 loader detected

What are my options legally if NYC company is not paying salary?

Why are thrust reversers not used down to taxi speeds?

Does this website provide consistent translation into Wookiee?

Why does this pattern in powers happen?

Why doesn't increasing the temperature of something like wood or paper set them on fire?

How to explain intravenous drug abuse to a 6-year-old?

I'm attempting to understand my 401k match and how much I need to contribute to maximize the match

What happens when the drag force exceeds the weight of an object falling into earth?

How would an instant or sorcery with an effect that targets work with Feather?

Is it safe to keep the GPU on 100% utilization for a very long time?

Is your maximum jump distance halved by grappling?

How is it believable that Euron could so easily pull off this ambush?

Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1

How to avoid making self and former employee look bad when reporting on fixing former employee's work?

What is the oldest instrument ever?

How to append code verbatim to .bashrc?

Can a character shove an enemy who is already prone?



Nodejs mongoose sub sub document search


How can I update NodeJS and NPM to the next versions?How do I update/upsert a document in Mongoose?NodeJs, Mocha and MongooseBest way to perform a full text search in MongoDB and MongooseHow to create Schema using mongodb(mongoose schema)?How to popoulate recursive schema references Mongodb, Mongoose, Express?Mongoose populate with match condition for nested documentMongoDB/ Mongoose many to many relationship - user, project and roleHow to make mongoose schema property of type (another) schema requiredMongoose: Add validators on the fly on some parameters depending on queries






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have schema like



const propertiesSchema = new Schema(
name:
type: String,
required: true
,
shortDescription: String,
totalArea: String,
address:
type: mongoose.Schema.Types.ObjectId,
ref: "Address",
required: true

)


and the address schema like this



const addressSchema = new Schema(
addressLine1:
type:String,
required:false
,
addressLine2:
type:String,
required:false
,
city:
type:mongoose.Schema.Types.ObjectId,
required:true,
ref:"City"

)


and i want to search city from propertiesSchema am using mongoose for the mongodb. and also i have optional searchData object like



searchData = 
"name":"test"
"city":"5c8f7f178dec7c20f4783c0d"



here the city id may be null and i need if the city id not null then only need to search city on propertiesSchema . please help to solve this problem. thank you..










share|improve this question




























    0















    I have schema like



    const propertiesSchema = new Schema(
    name:
    type: String,
    required: true
    ,
    shortDescription: String,
    totalArea: String,
    address:
    type: mongoose.Schema.Types.ObjectId,
    ref: "Address",
    required: true

    )


    and the address schema like this



    const addressSchema = new Schema(
    addressLine1:
    type:String,
    required:false
    ,
    addressLine2:
    type:String,
    required:false
    ,
    city:
    type:mongoose.Schema.Types.ObjectId,
    required:true,
    ref:"City"

    )


    and i want to search city from propertiesSchema am using mongoose for the mongodb. and also i have optional searchData object like



    searchData = 
    "name":"test"
    "city":"5c8f7f178dec7c20f4783c0d"



    here the city id may be null and i need if the city id not null then only need to search city on propertiesSchema . please help to solve this problem. thank you..










    share|improve this question
























      0












      0








      0


      1






      I have schema like



      const propertiesSchema = new Schema(
      name:
      type: String,
      required: true
      ,
      shortDescription: String,
      totalArea: String,
      address:
      type: mongoose.Schema.Types.ObjectId,
      ref: "Address",
      required: true

      )


      and the address schema like this



      const addressSchema = new Schema(
      addressLine1:
      type:String,
      required:false
      ,
      addressLine2:
      type:String,
      required:false
      ,
      city:
      type:mongoose.Schema.Types.ObjectId,
      required:true,
      ref:"City"

      )


      and i want to search city from propertiesSchema am using mongoose for the mongodb. and also i have optional searchData object like



      searchData = 
      "name":"test"
      "city":"5c8f7f178dec7c20f4783c0d"



      here the city id may be null and i need if the city id not null then only need to search city on propertiesSchema . please help to solve this problem. thank you..










      share|improve this question














      I have schema like



      const propertiesSchema = new Schema(
      name:
      type: String,
      required: true
      ,
      shortDescription: String,
      totalArea: String,
      address:
      type: mongoose.Schema.Types.ObjectId,
      ref: "Address",
      required: true

      )


      and the address schema like this



      const addressSchema = new Schema(
      addressLine1:
      type:String,
      required:false
      ,
      addressLine2:
      type:String,
      required:false
      ,
      city:
      type:mongoose.Schema.Types.ObjectId,
      required:true,
      ref:"City"

      )


      and i want to search city from propertiesSchema am using mongoose for the mongodb. and also i have optional searchData object like



      searchData = 
      "name":"test"
      "city":"5c8f7f178dec7c20f4783c0d"



      here the city id may be null and i need if the city id not null then only need to search city on propertiesSchema . please help to solve this problem. thank you..







      node.js mongoose mongoose-schema mongoose-populate nodejs-server






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 7:19









      soorajsooraj

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0














          As city is an nested object you can query that like



          "address.city"



          Eg: 

          searchData =
          "name":"test"
          "address.city":"5c8f7f178dec7c20f4783c0d"



          UPDATE



          '5c8f7f178dec7c20f4783c0d' is a string. You should use



          const mongoose = require('mongoose');
          mongoose.Types.ObjectId('5c8f7f178dec7c20f4783c0d');





          share|improve this answer

























          • but i get the error when i trying this UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value " city: '5c8f7f178dec7c20f4783c0d' " at path "address" for model "Properties"

            – sooraj
            Mar 29 at 5:43












          • but even now its return the empty array not returning the filtered array

            – sooraj
            Mar 29 at 12:07











          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%2f55311540%2fnodejs-mongoose-sub-sub-document-search%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














          As city is an nested object you can query that like



          "address.city"



          Eg: 

          searchData =
          "name":"test"
          "address.city":"5c8f7f178dec7c20f4783c0d"



          UPDATE



          '5c8f7f178dec7c20f4783c0d' is a string. You should use



          const mongoose = require('mongoose');
          mongoose.Types.ObjectId('5c8f7f178dec7c20f4783c0d');





          share|improve this answer

























          • but i get the error when i trying this UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value " city: '5c8f7f178dec7c20f4783c0d' " at path "address" for model "Properties"

            – sooraj
            Mar 29 at 5:43












          • but even now its return the empty array not returning the filtered array

            – sooraj
            Mar 29 at 12:07















          0














          As city is an nested object you can query that like



          "address.city"



          Eg: 

          searchData =
          "name":"test"
          "address.city":"5c8f7f178dec7c20f4783c0d"



          UPDATE



          '5c8f7f178dec7c20f4783c0d' is a string. You should use



          const mongoose = require('mongoose');
          mongoose.Types.ObjectId('5c8f7f178dec7c20f4783c0d');





          share|improve this answer

























          • but i get the error when i trying this UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value " city: '5c8f7f178dec7c20f4783c0d' " at path "address" for model "Properties"

            – sooraj
            Mar 29 at 5:43












          • but even now its return the empty array not returning the filtered array

            – sooraj
            Mar 29 at 12:07













          0












          0








          0







          As city is an nested object you can query that like



          "address.city"



          Eg: 

          searchData =
          "name":"test"
          "address.city":"5c8f7f178dec7c20f4783c0d"



          UPDATE



          '5c8f7f178dec7c20f4783c0d' is a string. You should use



          const mongoose = require('mongoose');
          mongoose.Types.ObjectId('5c8f7f178dec7c20f4783c0d');





          share|improve this answer















          As city is an nested object you can query that like



          "address.city"



          Eg: 

          searchData =
          "name":"test"
          "address.city":"5c8f7f178dec7c20f4783c0d"



          UPDATE



          '5c8f7f178dec7c20f4783c0d' is a string. You should use



          const mongoose = require('mongoose');
          mongoose.Types.ObjectId('5c8f7f178dec7c20f4783c0d');






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 29 at 8:37

























          answered Mar 29 at 5:01









          Viswanath LekshmananViswanath Lekshmanan

          7,63012953




          7,63012953












          • but i get the error when i trying this UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value " city: '5c8f7f178dec7c20f4783c0d' " at path "address" for model "Properties"

            – sooraj
            Mar 29 at 5:43












          • but even now its return the empty array not returning the filtered array

            – sooraj
            Mar 29 at 12:07

















          • but i get the error when i trying this UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value " city: '5c8f7f178dec7c20f4783c0d' " at path "address" for model "Properties"

            – sooraj
            Mar 29 at 5:43












          • but even now its return the empty array not returning the filtered array

            – sooraj
            Mar 29 at 12:07
















          but i get the error when i trying this UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value " city: '5c8f7f178dec7c20f4783c0d' " at path "address" for model "Properties"

          – sooraj
          Mar 29 at 5:43






          but i get the error when i trying this UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value " city: '5c8f7f178dec7c20f4783c0d' " at path "address" for model "Properties"

          – sooraj
          Mar 29 at 5:43














          but even now its return the empty array not returning the filtered array

          – sooraj
          Mar 29 at 12:07





          but even now its return the empty array not returning the filtered array

          – sooraj
          Mar 29 at 12:07



















          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%2f55311540%2fnodejs-mongoose-sub-sub-document-search%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

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript