The difference between { } and [ ] in mongoose? [duplicate]












0
















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.










share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb 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 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
















0
















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.










share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb 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 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














0












0








0









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.










share|improve this question















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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 5:57









Manfred TijerinoManfred Tijerino

192




192




marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb 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 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 mongodb
Users with the  mongodb badge can single-handedly close mongodb 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 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














  • 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












1 Answer
1






active

oldest

votes


















0














{ } can contain index data (with string indexes), while [ ] can only contain unindexed data (which numerically indexed by default).



As your example suggests,





  1. 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
    }
    }]



  2. Here data have string indexed



    social: {
    youtube: {
    type: String
    },
    twitter: {
    type: String
    },
    facebook: {
    type: String
    },
    linkedin: {
    type: String
    },
    instagram: {
    type: String
    }
    }







share|improve this answer





















  • 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 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














{ } can contain index data (with string indexes), while [ ] can only contain unindexed data (which numerically indexed by default).



As your example suggests,





  1. 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
    }
    }]



  2. Here data have string indexed



    social: {
    youtube: {
    type: String
    },
    twitter: {
    type: String
    },
    facebook: {
    type: String
    },
    linkedin: {
    type: String
    },
    instagram: {
    type: String
    }
    }







share|improve this answer





















  • 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


















0














{ } can contain index data (with string indexes), while [ ] can only contain unindexed data (which numerically indexed by default).



As your example suggests,





  1. 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
    }
    }]



  2. Here data have string indexed



    social: {
    youtube: {
    type: String
    },
    twitter: {
    type: String
    },
    facebook: {
    type: String
    },
    linkedin: {
    type: String
    },
    instagram: {
    type: String
    }
    }







share|improve this answer





















  • 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
















0












0








0







{ } can contain index data (with string indexes), while [ ] can only contain unindexed data (which numerically indexed by default).



As your example suggests,





  1. 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
    }
    }]



  2. Here data have string indexed



    social: {
    youtube: {
    type: String
    },
    twitter: {
    type: String
    },
    facebook: {
    type: String
    },
    linkedin: {
    type: String
    },
    instagram: {
    type: String
    }
    }







share|improve this answer















{ } can contain index data (with string indexes), while [ ] can only contain unindexed data (which numerically indexed by default).



As your example suggests,





  1. 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
    }
    }]



  2. Here data have string indexed



    social: {
    youtube: {
    type: String
    },
    twitter: {
    type: String
    },
    facebook: {
    type: String
    },
    linkedin: {
    type: String
    },
    instagram: {
    type: String
    }
    }








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 7:05









Enxtur

888913




888913










answered Nov 23 '18 at 6:03









Milind SinghMilind Singh

119115




119115








  • 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





    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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?