How to have a variable as key when using mongoose [duplicate]












0
















This question already has an answer here:




  • Associative array with mongoose schema?

    2 answers



  • Mongoose variable key name

    4 answers



  • How to use mongoose model schema with dynamic keys?

    1 answer




I am fetching a document that has an id that I am in position of.
For example the db has this kind of schema:



"id1": {
...
}



"id2": {
...
}



I am running a for over the json and data[i].address is id + i,
I want to update every key and value that are inside these id's but I can't use a variable as a key for mongoose, it throws an error.
Any trick to doing that?










share|improve this question













marked as duplicate by Neil Lunn javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 2:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • If you mean "within another property" then that's typically Mixed but you should seriously consider a regular array of objects with fixed key names. If you mean at the document root, then that's the { strict: false } option as noted.

    – Neil Lunn
    Nov 20 '18 at 2:14


















0
















This question already has an answer here:




  • Associative array with mongoose schema?

    2 answers



  • Mongoose variable key name

    4 answers



  • How to use mongoose model schema with dynamic keys?

    1 answer




I am fetching a document that has an id that I am in position of.
For example the db has this kind of schema:



"id1": {
...
}



"id2": {
...
}



I am running a for over the json and data[i].address is id + i,
I want to update every key and value that are inside these id's but I can't use a variable as a key for mongoose, it throws an error.
Any trick to doing that?










share|improve this question













marked as duplicate by Neil Lunn javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 2:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • If you mean "within another property" then that's typically Mixed but you should seriously consider a regular array of objects with fixed key names. If you mean at the document root, then that's the { strict: false } option as noted.

    – Neil Lunn
    Nov 20 '18 at 2:14
















0












0








0









This question already has an answer here:




  • Associative array with mongoose schema?

    2 answers



  • Mongoose variable key name

    4 answers



  • How to use mongoose model schema with dynamic keys?

    1 answer




I am fetching a document that has an id that I am in position of.
For example the db has this kind of schema:



"id1": {
...
}



"id2": {
...
}



I am running a for over the json and data[i].address is id + i,
I want to update every key and value that are inside these id's but I can't use a variable as a key for mongoose, it throws an error.
Any trick to doing that?










share|improve this question















This question already has an answer here:




  • Associative array with mongoose schema?

    2 answers



  • Mongoose variable key name

    4 answers



  • How to use mongoose model schema with dynamic keys?

    1 answer




I am fetching a document that has an id that I am in position of.
For example the db has this kind of schema:



"id1": {
...
}



"id2": {
...
}



I am running a for over the json and data[i].address is id + i,
I want to update every key and value that are inside these id's but I can't use a variable as a key for mongoose, it throws an error.
Any trick to doing that?





This question already has an answer here:




  • Associative array with mongoose schema?

    2 answers



  • Mongoose variable key name

    4 answers



  • How to use mongoose model schema with dynamic keys?

    1 answer








javascript node.js database mongodb mongoose






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 2:08









RandomizerRandomizer

9510




9510




marked as duplicate by Neil Lunn javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 2:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Neil Lunn javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 2:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • If you mean "within another property" then that's typically Mixed but you should seriously consider a regular array of objects with fixed key names. If you mean at the document root, then that's the { strict: false } option as noted.

    – Neil Lunn
    Nov 20 '18 at 2:14





















  • If you mean "within another property" then that's typically Mixed but you should seriously consider a regular array of objects with fixed key names. If you mean at the document root, then that's the { strict: false } option as noted.

    – Neil Lunn
    Nov 20 '18 at 2:14



















If you mean "within another property" then that's typically Mixed but you should seriously consider a regular array of objects with fixed key names. If you mean at the document root, then that's the { strict: false } option as noted.

– Neil Lunn
Nov 20 '18 at 2:14







If you mean "within another property" then that's typically Mixed but you should seriously consider a regular array of objects with fixed key names. If you mean at the document root, then that's the { strict: false } option as noted.

– Neil Lunn
Nov 20 '18 at 2:14














0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory