drudge / mongoose-timestamp Goto Github PK
View Code? Open in Web Editor NEWAdds createdAt and updatedAt date attributes that get auto-assigned to the most recent create/update timestamp
License: Other
Adds createdAt and updatedAt date attributes that get auto-assigned to the most recent create/update timestamp
License: Other
it is possible to disable a parameter so that it is not added?
for example:
mongoose.plugin(timestamps, {
createdAt: 'created_at',
updatedAt: false
});
Last update on mongoose brings this message in all scheemas on my bd.
All Updates and insertions are bring this error... Any solution?
Is there any way of defining indices for createdAt and updatedAt attributes?
I Worked with
Do you want to request a feature or report a bug?
I want to report a bug.
What is the current behavior?
When I working with a long process task like transfer data from MySQL to Mongo Atlas.
I try so many time but finally I got this:
(node:74121) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 2 to cluster0-shard-00-01-ug0nb.gcp.mongodb.net:27017 closed
at TLSSocket.<anonymous> (/Users/kayac/Projects/Work/Backend_Server/node_modules/mongodb-core/lib/connection/connection.js:352:9)
at Object.onceWrapper (events.js:288:20)
at TLSSocket.emit (events.js:200:13)
at net.js:586:12
at TCP.done (_tls_wrap.js:479:7)
And My config like this:
const db = await mongoose.connect(path, {
useNewUrlParser: true,
socketTimeoutMS: 600 * 1000,
connectTimeoutMS: 600 * 1000,
autoReconnect: true,
keepAlive: true,
reconnectTries: 30,
poolSize: 20,
});
socketTimeoutMS
and connectTimeoutMS
both doesn't help.
But I remove the
const timestamps = require('mongoose-timestamp');
Schema.plugin(timestamps);
And My task success.
Did mongoose timestamp auto close the TCP connection when process too long?
When setting the names of the createdAt and updatedAt properties, I am getting the following error:
node_modules/mongoose-timestamp/index.js:34
.get( function () {
^
TypeError: Object function Date() { [native code] } has no method 'get'
at timestampsPlugin (node_modules/mongoose-timestamp/index.js:34:8)
at Schema.plugin (node_modules/mongoose/lib/schema.js:570:3)
at Mongoose._applyPlugins (node_modules/mongoose/lib/index.js:403:12)
at Mongoose.model (node_modules/mongoose/lib/index.js:320:12)
at NativeConnection.Connection.model (node_modules/mongoose/lib/connection.js:600:23)
This also appears to be the error that is causing the Travis tests to fail on the continuing integration server.
when i do update to docement, field updatedAt
not updated with current Date time.
example my query
User.findByIdAndUpdate(id, { last_login: new Date() }).exec()
new Date() returns the server's time. You should use Date.now(), it returns the UTC time:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now
If i want to search in createdAt for specific timezone like Turkey timezone I have to convert it to uct?
When setting the names of the createdAt and updatedAt properties, I am getting the following error:
node_modules/mongoose-timestamp/index.js:34
.get( function () {
^
TypeError: Object function Date() { [native code] } has no method 'get'
at timestampsPlugin (node_modules/mongoose-timestamp/index.js:34:8)
at Schema.plugin (node_modules/mongoose/lib/schema.js:570:3)
at Mongoose._applyPlugins (node_modules/mongoose/lib/index.js:403:12)
at Mongoose.model (node_modules/mongoose/lib/index.js:320:12)
at NativeConnection.Connection.model (node_modules/mongoose/lib/connection.js:600:23)
This also appears to be the error that is causing the Travis tests to fail on the continuing integration server.
[TypeError: Cannot assign to read only property 'checkKeys' of true]
passport-local-mongoose 1.0.1
timestamps 0.4.0
var mongoose = require('mongoose');
var passportLocalMongoose = require('passport-local-mongoose');
var timestamps = require('mongoose-timestamp');
var Schema = mongoose.Schema;
exports.User = mongoose.model('User', new Schema({
username: {
type: String,
index: {
unique: true,
sparse: true
}
},
email: String
}, {
safe: true,
strict: true
}).plugin(passportLocalMongoose, {}).plugin(timestamps));
removing the timestamps plugin gets this working, but I liked the timestamps plugin.
Awesome plugin!
Can I add an extra option to createdAt and updatedAt to index it? Thanks.
Thanks for this plugin.
It would be nice if the column names 'updatedAt' and 'createdAt' could be customized.
In our case, we are considering adding it to an existing system where we already have a different naming convention established.
If a schema already has createdAt field, dont add it. Instead, add updatedAt field alone and maintain it. Vice versa for the updatedAt field.
Right now in version 0.3.0, this is the error I get when createdAt
is already there and if I use mongoose-timestamp in that schema.
/Users/Anand/xyz/node_modules/mongoose-timestamp/index.js:34
.get( function () {
^
TypeError: Object #<Object> has no method 'get'
at timestampsPlugin (/Users/Anand/xyz/node_modules/mongoose-timestamp/index.js:34:8)
at Schema.plugin (/Users/Anand/xyz/node_modules/mongoose/lib/schema.js:570:3)
at Object.<anonymous> (/Users/Anand/xyz/models/session_token.js:12:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/Anand/xyz/models/agent.js:17:20)
did an npm install mongoose-timestamp, implemented the plugin, as follows:
var timestamps = require('mongoose-timestamp');
var mongoose = require("mongoose");
var mongoSchema = mongoose.Schema;
var documentSchema = {
name: String,
isPayed: { type: Boolean, default: false }
};
documentSchema.plugin(timestamps);
module.exports = mongoose.model('documents', documentSchema);
When starting node, the compiler returns folliowing error:
PS C:\Users\paul\Programming\cli\ngEstrich_Server> node server
C:\Users\paul\Programming\cli\ngEstrich_Server\models\documents.js:65
documentSchema.plugin(timestamps);
^
Only works after save().
Was a mongoose limitation. Solved in mongoose 4. Please add support.
First: Thanks!
Second: I tried to research about the ability to enabled timestamps 'globally'.
Is there a way to enable timestamps to the mongoose object?
like with promises:
let mongoose = require('mongoose');
mongoose.Promise = global.Promise;
I believe that line 31 should be using createdAt
the variable, not "createdAt"
the string
if (schema.path('createdAt')) {
I have documents like below(i am using node.js and mongoose).
{
"id" : 1,
"name" : "strs",
"subs" : [
{
"sortorder" : 5,
"type" : "volvo"
},
{
"sortorder" : 2,
"type" : "benz"
}
]
}
{
"id" : 2,
"name" : "newname",
"subs" : [
{
"sortorder" : 3,
"type" : "volvo"
},
{
"sortorder" : 1,
"type" : "benz"
}
]
}
When i query for subs.type: volvo
, i need to sort the documents based on the sortorder for volvo
. I want output like below.
{
"id" : 2,
"name" : "newname",
"subs" : [
{
"sortorder" : 3,
"type" : "volvo"
},
{
"sortorder" : 1,
"type" : "benz"
}
]
}
{
"id" : 1,
"name" : "strs",
"subs" : [
{
"sortorder" : 5,
"type" : "volvo"
},
{
"sortorder" : 2,
"type" : "benz"
}
]
}
Correct me if I'm wrong, but this doesn't work:
Schema.plugin(require('mongoose-timestamp'), {
createdAt: 'created.at',
updatedAt: 'updated.at'
});
In earlier version 0.1.1
i was not specifying any createdAt in my schema file.
mongoose-timestamp used to add and and setupvirtuals
Now mongoose-timestamp is adding virtuals only if i have explicitly defined the createdAt field.
It seems like this plugin does not support insertMany
method because it won't call save
hook.
And I find this issue #723 may be helpful...
Can you support this feature ๏ผ
Thanks.
Hi,
It seems that mongoose has been supporting timestamps
option for quite a while now. Is there any need to use mongoose-timestamp
anymore or there is some sense to point people to mongoose docs and deprecate the module?
Thanks for all great work on this module, I've been using it for years and currently upgrading some of the old projects to use the latest mongoose, so that's how I stumbled upon this issue :)
http://mongoosejs.com/docs/guide.html#timestamps
Cheers,
Andrej
Hello,
I have the following in my code:
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
timestamps = require('mongoose-timestamp');
var ItemSchema = new Schema({
name: String
});
mongoose.plugin(timestamps, {
createdAt: 'added_at',
updatedAt: 'last_updated'
});
ItemSchema.plugin(timestamps);
however when I look at my item collection using mongo
command line I see that there is 4 properties (added_at
, last_updated
, createdAt
and updatedAt
)
what have I done wrong?
( @drudge ? )
No created or lastUpdated properties are populated
I have a situation where I am migrating some data and would like to preserve the modified dates from the original record. Can I manually set the created/modified dates and then have mongoose-timestamp skip its action so they are preserved?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.