Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongoose update createdAt

const schema = mongoose.Schema({
  	name: String,
    createdAt: { type: Date, default: Date.now }
}, {
    timestamps: { createdAt: false, updatedAt: true }
})

const Test = mongoose.model('test', schema);

const john = await Test.create({name: 'John Doe'});
console.log(john);

// Now that will work
const updatedJohn = await Test.findOneAndUpdate({name: 'John Doe'}, { createdAt: Date.now() });
console.log(updatedJohn);
Comment

PREVIOUS NEXT
Code Example
Javascript :: bottom tab navigator react native transparent 
Javascript :: trunc number javascript 
Javascript :: pushing to an array 
Javascript :: flattenDeep in es 6 without lodash 
Javascript :: js filter undefined from array 
Javascript :: javascript is a string numeric 
Javascript :: check if localstorage key exists js 
Javascript :: if select option disabled jquerz 
Javascript :: encrypt data using SHA256 algorithm in JavaScript 
Javascript :: req.url 
Javascript :: celsius to fahrenheit in javascript 
Javascript :: input length material Ui Design 
Javascript :: javascript access php variable 
Javascript :: jquery keep scroll position 
Javascript :: ant design not working in react js 
Javascript :: javascript random number in range 
Javascript :: remove element from dictionary javascript 
Javascript :: merge data to json js 
Javascript :: sort array of objects javascript by date 
Javascript :: js date dd.mm.yyyy 
Javascript :: unexpected token react native stack navigation 
Javascript :: history.push 
Javascript :: vue computed composition api 
Javascript :: merge two objects javascript 
Javascript :: should i use google pay 
Javascript :: throttling function in javascript 
Javascript :: react 17 hot reload not working 
Javascript :: how to get value in formgroup in angular 
Javascript :: js get option value 
Javascript :: install node js 14 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =