A
A
Artyom N2012-12-22 21:54:32
JavaScript
Artyom N, 2012-12-22 21:54:32

How to store a 2D array in MongoDB?

Good evening! I am learning Node.JS in conjunction with MongoDB. To interact with the database, I use the mongoose framework. There is this code:

db = mongoose.connect ( 'mongodb://localhost/test' );
var ServerSchema = mongoose.Schema ( { key: String, users: Number, size: Number, map: Array } );
var Server = mongoose.model ( 'Server', serverSchema );

Server.findOne( { key: key }, 'users map', function ( err, serv ) {
  if ( err ) return console.error ( err );
  console.log ( serv.map );
});


Initially a two-dimensional array is mapreturned one-dimensional. How to implement saving?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Huseynov, 2012-12-23
@kibergus

Array is a one-dimensional array. A two-dimensional array is an Array that stores Arrays.

S
Silver_Clash, 2012-12-23
@Silver_Clash

Generally speaking, there are no two-dimensional arrays in js.
Try the native driver first and play around with different collection options.

K
Keyten, 2012-12-30
@Keyten

Try JSON.stringify and JSON.parse.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question