How to limit an array size in MongoDB? -


is there way can limit number of elements can added mongodb array? have tables collection attendees array should contain 10 elements seats).

thank you!

you can use $slice modifier $push when update document:

$push: {"field": $each: ["val1", "val2"], $slice: -10} 

this cause field consist of last 10 elements (giving "rolling window" of values pushed field).


Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

java - Incorrect order of records in M-M relationship in hibernate -