How to delete a document in documentdb using c# where i have variable with timestamp by quering it - azure

I have a document in with data like following format.
[
{
"TimeStamp": "3/18/2015 7:57:21 PM",
}
]
I need to query this document only with date(3/18/2015) and delete that document using c#. Time in the TimeStamp (7:57:21 PM) should not be queried. How can I do it?
If there are multiple records with the same date, i need to delete all those documents.
Thanks
Naveen

Today you need to know the doc._self to delete a Document.
So do a query for the document(s) based on any criteria you like, including the timestamp (no reason to not use this, it's there for that reason). Then execute a delete statement against each document found.
If you want to do this in a batch to minimize server roundtrips, consider doing this in a stored procedure, similar to our published BulkImport.js script.

Related

Couchdb how to get the timestamp of the last modified database?

Does anyone know how to get the last timestamp that a specific database was modified?
The API _changes does not provide that information. Thank you.
UPDATE
How to retrieve the last date /time that the database had anew document inserted or a modified one.
CouchDB does not record the time that each change occurred, so if you need this functionality you need to a add a timestamp into the document e.g.
{
"_id": "myid",
"name": "Bob",
"email": "bob#aol.com",
"timestamp": 1657614546263
}
Then a MapReduce view will allow you to query documents by timestamp:
function(doc) {
emit(doc.timestamp)
}
To get a the latest change you would query the resultant view with ?descending=true&limit=1 to get the most recently modified document:
GET /mydb/_design/myview/_view/myview?descending=true&limit=1&include_docs=true`
Alternatively, you can use a document id that has a timestamp encoded within it. See this blog post which shows how documents with time-sortable ids allow easy querying of the latest documents to be added.

get all docs from couchDB updated in a specific time range

I would like to get all the docs in couchDb updated in a specific time range.
I'm using the below API but I don't get any result.
/_all_docs?startkey="2019-01-01T00:00:00Z"&endkey="2020-01-01T00:00:00Z"
Any suggestions are welcome.
Andrea
_all_docs's key is the document ID, not timestamp. For your query to be useful, you'll need to create a custom view based on a timestamp (and ensure the timestamp is updated by your code).

Querying for new and changed documents in SharePoint

We need to query SharePoint for new and changed documents. The 'Write' property gives the modified timestamp from inside the document metadata (i.e. inside the document properties), not the time the document was added to SharePoint.
I've tried this query:
and(IsDocument:true, write:range(2018-02-16, max) )
but the write time is based on the date embedded inside the document (not the date the document was added to SharePoint).
Does anyone have any guidance they can share?
Update with more test results:
Digging into the properties, I think that the DiscoveredTime property might be what I'm looking for. This documentation (https://technet.microsoft.com/en-us/library/jj219630.aspx) says that the DiscoveredTime property isn't searchable, but I am able to search using this:
and(IsDocument:true, DiscoveredTime:range(2018-02-16, max) )
I can't find anywhere that explains what DiscoveredTime actually is, but it seems to correlate with when the document was added to SP.

How can I reduce a collection by keeping only change points?

I have a Collection exampled below. This data is pulled from an endpoint every twenty minutes on a cron job.
{"id":AFFD6,"empty":8,"capacity":15,"ready":6,"t":1474370406,"_id":"kROabyTIQ5eNoIf1"}
{"id":AFFD6,"empty":9,"capacity":15,"ready":5,"t":1474116005,"_id":"kX0DpoZ5fkMr2ezg"}
{"id":AFFD6,"empty":9,"capacity":15,"ready":5,"t":1474684808,"_id":"ken1WRN47PTW159H"}
{"id":AFFD6,"empty":9,"capacity":15,"ready":5,"t":1474117205,"_id":"kes1gDlG1sBjgV1R"}
{"id":AFFD6,"empty":10,"capacity":15,"ready":4,"t":1474264806,"_id":"khILUjzGEPOn0c2P"}
{"id":AFFD6,"empty":9,"capacity":15,"ready":5,"t":1474275606,"_id":"ko9r8u860es7E2hI"}
{"id":AFFD6,"empty":9,"capacity":15,"ready":5,"t":1474591207,"_id":"kpLS6mCtkIiffTrN"}
I want to discard any document (row) that doesn't show a change in the empty (and consequently ready). My goal is to find the most recent time stamp where these values have changed with in this collection.
Better illustrated, I want to reduce it to where the values change as such:
{"id":AFFD6,"empty":8,"capacity":15,"ready":6,"t":1474370406,"_id":"kROabyTIQ5eNoIf1"}
{"id":AFFD6,"empty":9,"capacity":15,"ready":5,"t":1474117205,"_id":"kes1gDlG1sBjgV1R"}
{"id":AFFD6,"empty":10,"capacity":15,"ready":4,"t":1474264806,"_id":"khILUjzGEPOn0c2P"}
{"id":AFFD6,"empty":9,"capacity":15,"ready":5,"t":1474591207,"_id":"kpLS6mCtkIiffTrN"}
Can I do this at the in a MongoDB query? Or am I better off with a JavaScript filter function?
MongoDB allows you to specify a unique constraint on an index. These constraints prevent applications from inserting documents that have duplicate values for the inserted fields.
Use the following code to make unique
db.collection.createIndex( { "id": 1 }, { unique: true } )
Also refer the MongoDB documentation for more clarification.

How to get last created document in couchdb?

How can I get last created document in couchdb? Maybe some how I can use _changes feature of couchdb? But documentation says, that I only can get list of document, ordered by first created document, ant there is no way to change order.
So how can I get last created document?
You can get the changes feed in descending order as it's also a view.
GET /dbname/_changes?descending=true
You can use limit= as well, so;
GET /dbname/_changes?descending=true&limit=1
will give the latest update.
Your only surefire way to get the last created document is to include a timestamp (created_at or something) with your document. From there, you just need a simple view to output all the docs by their creation date.
I was going to suggest using the last_seq information from the database, but the sequence number changes with every single write, and replication also complicates the matter further.

Resources