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;
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
add a comment |
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
add a comment |
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
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
node.js mongoose mongoose-schema mongoose-populate nodejs-server
asked Mar 23 at 7:19
soorajsooraj
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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');
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
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%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
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');
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
add a comment |
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');
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
add a comment |
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');
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');
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
add a comment |
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
add a comment |
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%2f55311540%2fnodejs-mongoose-sub-sub-document-search%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