const mongoose = require('mongoose');
const assert = require('assert')
const Author = require('../models/author');
describe('Nesting Documents', function(){
//Create tests
it('Create an author with sub-documents', function(done){
var pat = new Author({
name: 'Patrick Ruffus',
books:[{title:'Name of the wind', pages: 400}]
});
pat.save().then(function(){
Author.findOne({name:'Patrick Ruffus'}).then(function(record){
assert(record.books.length === 1);
done();
})
})
})
it('Add a book to an existing author', function(done){
var rus = new Author({
name: 'Ruskin Bond',
books:[{title:'The eyes have it', pages: 400}]
});
rus.save().then(function(){
Author.findOne({name:'Ruskin Bond'}).then(function(record){
record.books.push({title:"7 husband", pages:200});
record.save().then(function(){
Author.findOne({ name: 'Ruskin Bond' }).then(function(record){
assert(record.books.length===2);
done();
})
})
})
})
})
})
Read next

One-step to prevent potential NoSQL Injection in your mongodb application
Gurkirat Singh -

Docker + Flask + Vue + Nginx + MongoDB- deployment and development in one package (3)
Herbz -

Compile PHP 7.3.13 on CentOS 7 with OCI8 and MongoDB extension.
Bidhan Khatri -

Passo a passo de como criar seu Pokedex com Spring WebFlux
Ana Beatriz -
Discussion (0)