J
J
Jumandjilos2018-06-12 21:25:34
MongoDB
Jumandjilos, 2018-06-12 21:25:34

How to turn a collection into an array using mongoose?

In mongoDB, you can use toArray to turn a collection into an array and work with it, but how can you turn a mongoose model into an array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-06-14
@atcrew

Model in an array using mongoose - no way. An array of models, yes, an array of a model (essentially an ordinary object), no matter how. Think about what exactly you want to see in the array. If for example the model is {_id: ObjectId, Name: 'John', AGE: 22} then what is the array? Of course, you can convert an object into anything even in [ [_id, ObjectId], [Name, John], [AGE, 22] ], but this is by hand)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question