The difference between { } and [ ] in mongoose? [duplicate]
This question already has an answer here:
When to use an object or an array in javascript? [duplicate]
7 answers
What is the main difference between { } and [ ] ?
I want to know when to use it and how stores the data
education: [
{
school: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}
]
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
}
I would love to see some examples to understand where to use it and when not to use it.
node.js mongodb mongoose nosql
marked as duplicate by Neil Lunn
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 23 '18 at 6:04
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.
add a comment |
This question already has an answer here:
When to use an object or an array in javascript? [duplicate]
7 answers
What is the main difference between { } and [ ] ?
I want to know when to use it and how stores the data
education: [
{
school: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}
]
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
}
I would love to see some examples to understand where to use it and when not to use it.
node.js mongodb mongoose nosql
marked as duplicate by Neil Lunn
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 23 '18 at 6:04
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.
2
google.com/search?q=javascript+arrays+and+objects
– Neil Lunn
Nov 23 '18 at 6:02
2
Though the question likely illustrates a lack of understanding for JavaScript itself and the other references will help, then I would also suggest reading the MongoDB manual section on Data Modeling as a good place to start
– Neil Lunn
Nov 23 '18 at 6:13
add a comment |
This question already has an answer here:
When to use an object or an array in javascript? [duplicate]
7 answers
What is the main difference between { } and [ ] ?
I want to know when to use it and how stores the data
education: [
{
school: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}
]
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
}
I would love to see some examples to understand where to use it and when not to use it.
node.js mongodb mongoose nosql
This question already has an answer here:
When to use an object or an array in javascript? [duplicate]
7 answers
What is the main difference between { } and [ ] ?
I want to know when to use it and how stores the data
education: [
{
school: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}
]
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
}
I would love to see some examples to understand where to use it and when not to use it.
This question already has an answer here:
When to use an object or an array in javascript? [duplicate]
7 answers
node.js mongodb mongoose nosql
node.js mongodb mongoose nosql
asked Nov 23 '18 at 5:57
Manfred Tijerino
162
162
marked as duplicate by Neil Lunn
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 23 '18 at 6:04
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
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 23 '18 at 6:04
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.
2
google.com/search?q=javascript+arrays+and+objects
– Neil Lunn
Nov 23 '18 at 6:02
2
Though the question likely illustrates a lack of understanding for JavaScript itself and the other references will help, then I would also suggest reading the MongoDB manual section on Data Modeling as a good place to start
– Neil Lunn
Nov 23 '18 at 6:13
add a comment |
2
google.com/search?q=javascript+arrays+and+objects
– Neil Lunn
Nov 23 '18 at 6:02
2
Though the question likely illustrates a lack of understanding for JavaScript itself and the other references will help, then I would also suggest reading the MongoDB manual section on Data Modeling as a good place to start
– Neil Lunn
Nov 23 '18 at 6:13
2
2
google.com/search?q=javascript+arrays+and+objects
– Neil Lunn
Nov 23 '18 at 6:02
google.com/search?q=javascript+arrays+and+objects
– Neil Lunn
Nov 23 '18 at 6:02
2
2
Though the question likely illustrates a lack of understanding for JavaScript itself and the other references will help, then I would also suggest reading the MongoDB manual section on Data Modeling as a good place to start
– Neil Lunn
Nov 23 '18 at 6:13
Though the question likely illustrates a lack of understanding for JavaScript itself and the other references will help, then I would also suggest reading the MongoDB manual section on Data Modeling as a good place to start
– Neil Lunn
Nov 23 '18 at 6:13
add a comment |
1 Answer
1
active
oldest
votes
{ }
can contain index data (with string indexes), while [ ]
can only contain unindexed data (which numerically indexed by default).
As your example suggests,
Here, data is on 0 index by default:
education: [{
school: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}]
Here data have string indexed
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
}
1
while [ ] can only contain unindexed data
This is unfortunately false. Arrays can contain pretty much the same sort of key-value pairs as objects, it's just an abuse of their structure to do so. Also, your code doesn't look great, strings require delimiters.
– CertainPerformance
Nov 23 '18 at 6:07
@CertainPerformance I know its "(which numerically indexed by default)" as added. Also, your code doesn't look great, strings require delimiters. I didn't get??
– Milind Singh
Nov 23 '18 at 6:09
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
{ }
can contain index data (with string indexes), while [ ]
can only contain unindexed data (which numerically indexed by default).
As your example suggests,
Here, data is on 0 index by default:
education: [{
school: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}]
Here data have string indexed
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
}
1
while [ ] can only contain unindexed data
This is unfortunately false. Arrays can contain pretty much the same sort of key-value pairs as objects, it's just an abuse of their structure to do so. Also, your code doesn't look great, strings require delimiters.
– CertainPerformance
Nov 23 '18 at 6:07
@CertainPerformance I know its "(which numerically indexed by default)" as added. Also, your code doesn't look great, strings require delimiters. I didn't get??
– Milind Singh
Nov 23 '18 at 6:09
add a comment |
{ }
can contain index data (with string indexes), while [ ]
can only contain unindexed data (which numerically indexed by default).
As your example suggests,
Here, data is on 0 index by default:
education: [{
school: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}]
Here data have string indexed
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
}
1
while [ ] can only contain unindexed data
This is unfortunately false. Arrays can contain pretty much the same sort of key-value pairs as objects, it's just an abuse of their structure to do so. Also, your code doesn't look great, strings require delimiters.
– CertainPerformance
Nov 23 '18 at 6:07
@CertainPerformance I know its "(which numerically indexed by default)" as added. Also, your code doesn't look great, strings require delimiters. I didn't get??
– Milind Singh
Nov 23 '18 at 6:09
add a comment |
{ }
can contain index data (with string indexes), while [ ]
can only contain unindexed data (which numerically indexed by default).
As your example suggests,
Here, data is on 0 index by default:
education: [{
school: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}]
Here data have string indexed
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
}
{ }
can contain index data (with string indexes), while [ ]
can only contain unindexed data (which numerically indexed by default).
As your example suggests,
Here, data is on 0 index by default:
education: [{
school: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}]
Here data have string indexed
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
}
edited Nov 23 '18 at 7:05
Enxtur
838712
838712
answered Nov 23 '18 at 6:03
Milind Singh
220113
220113
1
while [ ] can only contain unindexed data
This is unfortunately false. Arrays can contain pretty much the same sort of key-value pairs as objects, it's just an abuse of their structure to do so. Also, your code doesn't look great, strings require delimiters.
– CertainPerformance
Nov 23 '18 at 6:07
@CertainPerformance I know its "(which numerically indexed by default)" as added. Also, your code doesn't look great, strings require delimiters. I didn't get??
– Milind Singh
Nov 23 '18 at 6:09
add a comment |
1
while [ ] can only contain unindexed data
This is unfortunately false. Arrays can contain pretty much the same sort of key-value pairs as objects, it's just an abuse of their structure to do so. Also, your code doesn't look great, strings require delimiters.
– CertainPerformance
Nov 23 '18 at 6:07
@CertainPerformance I know its "(which numerically indexed by default)" as added. Also, your code doesn't look great, strings require delimiters. I didn't get??
– Milind Singh
Nov 23 '18 at 6:09
1
1
while [ ] can only contain unindexed data
This is unfortunately false. Arrays can contain pretty much the same sort of key-value pairs as objects, it's just an abuse of their structure to do so. Also, your code doesn't look great, strings require delimiters.– CertainPerformance
Nov 23 '18 at 6:07
while [ ] can only contain unindexed data
This is unfortunately false. Arrays can contain pretty much the same sort of key-value pairs as objects, it's just an abuse of their structure to do so. Also, your code doesn't look great, strings require delimiters.– CertainPerformance
Nov 23 '18 at 6:07
@CertainPerformance I know its "(which numerically indexed by default)" as added. Also, your code doesn't look great, strings require delimiters. I didn't get??
– Milind Singh
Nov 23 '18 at 6:09
@CertainPerformance I know its "(which numerically indexed by default)" as added. Also, your code doesn't look great, strings require delimiters. I didn't get??
– Milind Singh
Nov 23 '18 at 6:09
add a comment |
2
google.com/search?q=javascript+arrays+and+objects
– Neil Lunn
Nov 23 '18 at 6:02
2
Though the question likely illustrates a lack of understanding for JavaScript itself and the other references will help, then I would also suggest reading the MongoDB manual section on Data Modeling as a good place to start
– Neil Lunn
Nov 23 '18 at 6:13