I have searched the google docs api for quite some time now and am attempting to find a way to retrieve timestamp information. For example, if I make a google doc and write a bunch of stuff in it, there was a specific point in time that I wrote those notes. Perhaps this could be retrievable through the version history of the doc.
I can't seem to find any way to access this timestamp information from the google docs api reference https://developers.google.com/docs/api/reference/rest
and was wondering if anyone has dealt with this kind of thing before. Thanks!
Use the Drive API
Specifically the revisions resource
Which will return objects of this type:
{
"kind": "drive#revision",
"id": string,
"mimeType": string,
"modifiedTime": datetime,
"keepForever": boolean,
"published": boolean,
"publishedLink": string,
"publishAuto": boolean,
"publishedOutsideDomain": boolean,
"lastModifyingUser": {
"kind": "drive#user",
"displayName": string,
"photoLink": string,
"me": boolean,
"permissionId": string,
"emailAddress": string
},
"originalFilename": string,
"md5Checksum": string,
"size": long,
"exportLinks": {
(key): string
}
}
The Docs API will get your document with the current revision ID, which you can use in parallel with calls to the Drive API.
Though getting the actual change between revisions may be more complicated. You may have to export the revision in a text format and then compare the revisions to see what has changed.
Related
Should we send a null or empty string value on request ?
I mean we have an optional value and it had a value currently. If use want to delete value of that optional field, should API understand null or empty is delete value ?
Ex:
{
name: { type: String, required: true },
phone: { type: String, required: false }
}
In database:
{
name: "Alex",
phone: "012-333.222"
}
And now, use want to delete their phone number
Should we define looks like:
PUT /users/user-id-1
{
phone: null
}
Seems it's a bad convention
Should we send a null or empty string value on request ?
REST doesn't care; which is to say that it tells us to use self descriptive messages to transfer documents over a network, but it doesn't tell us what the representations of the documents should be.
Where you want to be looking instead is at message schema definitions, and in particular designing your schema in such a way that it can be extended in backwards compatible ways. The XML community spent a lot of time exploring those ideas; Orchard 2004 might be a good starting point.
In HTTP, the basic mechanism for describing a change to a resource is to use a PUT command with a copy of the new representation. So a request would probably look like:
PUT /users/user-id-1
Content-Type: application/json
{
name: "Alex",
phone: null
}
If your schema is defined in such a way that the phone field is optional, and that optional and null are equivalent (as opposed to some other implied value), then you might equivalently use:
PUT /users/user-id-1
Content-Type: application/json
{
name: "Alex"
}
In cases where the representation is very big, and the changes you are making are small, you might want to support PATCH.
PATCH /users/user-id-1
Content-Type: application/merge-patch+json
{
phone: null
}
Note that the HTTP PATCH specification includes the Allow-Patch which allows clients to discover which patch representations a server supports for a resource.
Though, in front end, usually it depends on whether use the delete button or, they just leave the field empty
phone: '' - means user left field empty
phone: null - means user click on delete field button. You decide whether to delete the field, or just set the document field to null.
I will usually delete the field, since it is now useless.
If you want to update only one property in a document you can use PATCH method instead of PUT method and your code should look like this:
PATCH /users/user-id-1
{
phone: ""
}
I feel as though this is a simple question, but after doing google searches and looking at the mongoose documentation, I have not found a good answer (or at least one that I understand).
I want to include in the Profile Schema a Date of Birth Block. Now, this is my idea but I am unsure if this will work well within MongoDB.
I want to be able to have the User enter this information into their profile, and save it into the database.
birthday: {
day: {
type: Number
},
month: {
type: Number
},
year: {
type: Number
}
Is this the best method? does it cause problems in the long run? what is your guys opinion on the proper way to using Node.Js/Mongoose Schemas and using birthdates?
I appreciate the help guys.
Why not just use something like this?
birthday: { type: Date }
Whenever user inputs all the three fields, combine it to form the birthday and save it as date object. This seems much cleaner and it's easy to query too, considering mongo supports aggregation on fields like $month.
Birth-date format for mongoose Schema
dateOfBirth: {
type: Date,
required: true,
trim: true,
}
I am currently building a Mongo, Node, Express web app where deals are rendered on the screen in a list if they are "active" . However, I would like to programtically change the "active" status of a deal to (see below for dealSchema) at the "dealEndingDate". Think of it like a deal expiring. Is there some sort of listener I can add to constantly troll the database and update the documents... I welcome all suggestions. Thank you!
{
"_id": {
"$oid": "5a63c974aa17eb49c5260815"
},
"dealHeadline": "Test",
"active": true,
"dealBeginningTime": {
"$date": "2018-01-20T06:00:00.000Z"},
"dealEndingTime": {
"$date": "2018-01-22T23:45:00.000Z"}
}
A cronjob can be a solution for you .
An alternative way of doing this is to use expires, i.e. dealEndingTime: { type: Date, expires: '60s' }. Please note that this will remove the entire document 60 seconds after the set date. If you still want to keep the document, you can set up a separate Deal collection, where all your deals are stored. Then you can reference the deals for each document by using ObjectId: deals: [{_id: { type: Schema.Types.ObjectId, ref: 'deal' } Then simply checking the length of the array will reveal if there are any active deals for that document.
I hope this is useful to you!
I've looked around left and right, I wrote some demo code, wrote some tests to implement a school management system.
What I want to know from people more used to mongoose development is how would be the best practice to create this schema in a way that made it possible to add as many address, and contact fees as I want from this single document.
I made my own solution, but I don't know if it is the most elegant and feasible way, I want an opinion from seasoned people.
Should I create separate models for address, email and phone numbers?
I created this schema. It still has some pseudo-code, but for giving the general idea is fine.
var student = {
name: String,
surname: String,
currentClass: {
type: mongoose.Schema.Types.ObjectId,
ref: "Classes"
},
birthday: {
year: Number,
month: Number,
day: Number
},
address: [{
name: String,
zip: Number,
address: String,
city: String,
state: String,
complement: String
}]
accountable: {
name: String,
surname: String,
email: [{
type: String,
required: true,
lowercase: true
}],
phone: [String, String]
}
My sollution was, by using html, creating a new "email" or "address" fields as the user requested by clickinking in the propper button. This generated a new input field with a name that followed a pattern like:
email1, email2, email3, email4
And so, when the user sent the data, if we were creating a new student I would first create the array with the data and send it to mongoose.
In case of updating, I would get the already created emails and add it to the new array with the newEmails.concat(old_emails)
To design the database, there are many situations for it:
1 to 1, 1 to many, many to many.
One to one: you should to put the strong object inside the other, for example:a person can have only one passport, then we should put passport object inside the person object.
One to Many, 3 cases for one to many.
One to Few:few is less than 100 objects,Then you should add the few as list in the one object, for example:
A person can have multiple addresses as in your example above.
One to Many:many is Thousands, then you should put the primary keys of the many in a list inside the the one object.
One to Too many: then do not do the previous solution, but instead add the primary of the one in every objects of the many.
And finally, Many to Many: you should put them as list in both sides.
Check the below references:
https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-1
https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-2
https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-3
Morover, for this part phone: [String, String], you should make it phone: [String]
I'm developing a REST api using node.js + mongoose. I have a model which has few nested arrays within it. I have a put endpoint to update the document. However to add an object into the sub-array, do i need a separate endpoint or is there a way to use the same put endpoint? `
companyName: String,
city: String,
pincode: Number,
managers: [{
name: String,
dob: Date,
gender: String,
highestEducation: String,
email: String,
phoneNumbers: [{phoneNumber: Number}],
}],`
I have an endpoint ../api/customer for updating the document. It replaces the existing document with the json that im supplying. So, if i want to add a manager (not replace the existing manager), do i need a seperate endpoint just for this? What is the optimized solution?