node.js - Proper way to create indexes during deployment -


i creating expressjs api , using mongodb. have decent understanding of indexes , understand expensive create when there data in database.

in ms sql server create indexes when creating database tables. question handle creation of indexes in post call in express app or achieve using scripts when deploymening application?

for example need geospatial indexing.

would index creation handled in express app this?

//express post call let col = db.collection( 'collection' ); col.createindex( // someindex ); col.insertone( //some document ); 

i looking best method creating 'initial' state of mongodb , creating indexes need collections before these collections contain documents.

so, may happen, have lot of data in database while deployment , not want indexing terrible. here's mongodb can help. can indexing in background not prevent read , write operations database while index builds.a simple command:

db.collection.createindex( { a: 1 }, { background: true } ) 

check manual details.

https://docs.mongodb.org/manual/tutorial/build-indexes-in-the-background/


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -