Sails Wateline find with mongodb Object Id not working - mongodb

I've an application with sails.js and mongodb.
The sails rest api works fine for create. It also works fine when I access it as "http://localhost:1337/student" but not working when finding a specific document with id "http://localhost:1337/student/54e57a98469768d40df7fb24".
The object id in db is stored as _id : ObjectId("54e57a9e469768d40df7fb25").
I also tried to update record in Controller but that also seems to be NOT working:
Student.update({id:Student.mongo.objectId(req.body.id)},{is_active:0}).exec(function(err, data){
............
});
Any help will be appreciated.
Thanks.

I do notice your ids are different between your URL and the mongo paste, so make sure that is on. Also I'd recommend installing the postman packaged app in the google chrome store, its really nice for doing rest work. If you watch the sailscasts videos by nathanirl on YouTube you'll see some nice examples of what it can do.
Also make sure your blueprints.js in config file is setup with. Actions, shortcuts and rest set to true

Related

Firestore how to set serverTimestamp behaviour in Flutter?

I am trying to make my app save local changes (e.g. saving notes) to firestore db while it is offline. When I use DateTime.now() for timeCreated, everything (most of job) works, but obviously, it is not correct time. I found solution with using FieldValue.serverTimestamp() to have correct time, but once I try to use it while app is offline, I can't get a value of previous timeCreated fields. Furthermore, I found out about DocumentSnapshot.ServerTimestampBehavior in firebase docs, and now I don't have clue how to use it or is it even available in flutter mobile apps. Link for Android: Android docs.
EDIT
I already gave up from using serverTimestamp, but I gave it another shot and successfully solved it. The problem was that I used hasPendingWriteson whole query, instead on single document which is added (updated) offline. In this article everything is described link. Still, I didn't find solution for my question.

Setting a value in Frappe application isn't reflected in ERPNext GUI

I have added a 'number_of_members' value to the Customer DocType via customization.
In my application I have tried several ways to update the value. However the value never updates in the webpage. I feel like I'm missing some sort of save or update or commit step.
For example I have tried:
frappe.client.set_value('Customer', '00042', 'number_of_members', 8887)
frappe.set_value('Customer', '00042', 'number_of_members', 8887)
frappe.db.set_value('Customer', '00042', 'number_of_members', 8887)
and also
customer = frappe.get_doc('Customer', '00042')
customer.number_of_members = 8887
customer.save()
In each case I can do something like frappe.get_value, or frappe.get_doc and it shows the value is set to 8887. However it never updates in the web side. This is what makes me think I'm updating some sort of cache or database transaction and I need some way to save it, but have not had any luck.
I am mostly testing this via bench console if that has any bearing on it, but I've tried a couple of the methods in my application code as well.
Relevant documentation:
Frappe Developer API - Document
Frappe Developer API - Database
Turns out the answer is to call frappe.db.commit() after making changes. If someone can point this out in the documentation so I can better understand how I'm missing stuff, I would appreciate it.
I also noticed if you try to Save something in the UI before you send frappe.db.commit() the UI will hang.

Manatee.Trello: Simple CRUD App for Updating Cards

I need to develop a simple CRUD console app to update a list of Trello cards from a CSV file. I'll run the app in TaskScheduler every night. I've installed #gregsdennis Manatee.Trello packages (impressive code!) but cannot find a single (complete example) of anything like this anywhere. All I've managed to do is auth in with app key and tokedn.
Is there a resource out there that shows simple (full) examples of how to get started? #gregsdennis—the C# libraries are extensive and obviously well thought out—I just need a jump start to get me going. Thanks to all in advance!
Here's the documentation site: https://gregsdennis.github.io/Manatee.Trello/usage/getting-started.html

PouchDB Extension not showing second database

I’ve only just started using PouchDB (with Ionic), so I’m still working on wrapping my head around everything and getting it all set up (all my experience is in MySQL).
I have a simple Ionic app working with PouchDB and some basic CRUD abilities, now I’m trying to visualise what I’m doing using the PouchDB Extension for Chrome. So far so good, I click a “+” button to add an item to a list and the new database shows up under “Databases” in the PouchDB Extension.
Now I’m doing the exact same thing for a second database, and it’ll put my newly created items in a separate list, all seems to be good, I can edit and delete these items as well, just like in the first database. But this second database won’t show up in the PouchDB Extension and for the life of me I can’t figure out why, I’m doing exactly the same as with the first database.
This is part of my code for the first database:
function initDB() {
_db = new PouchDB('threads');
};
function addThread(thread) {
return $q.when(_db.post(thread));
};
And then this is what I'm doing for the second one:
function initDB() {
_db = new PouchDB('categories');
};
function addCategory(category) {
return $q.when(_db.post(category));
};
Btw: This is the tutorial I've followed to get the PouchDB part of my Ionic app working. (Basically just followed part of it twice to get the second database working)
Edit: So I just found the "application" tab in Chrome's developer tools (again, I come from MySQL databases, never worked with local storage before). I can view the Web SQL databases there and both my databases do show up there, but still only the first one is shown in the PouchDB extension :(
Edit 2: Alright this is turning into a whole different problem. I was aware that the PouchDB extension doesn't support the websql adapter, I thought PouchDB defaulted to IndexedDB but apparently idb isn't available in my Chrome installation? If I do the following to explicitly say I want to use the IndexedDB adapter:
_db = new PouchDB('threads', {adapter: 'idb'});
I get the following error: Error: Invalid Adapter: idb
If open the page in either Firefox or Chrome Canary I get no errors at all, and after adding the PouchDB inspector to Canary everything works as I want it to. I did update Chrome to the latest version (Version 53.0.2785.101 (64-bit)).
Any ideas as to why my regular Chrome installation doesn't support IndexedDB? (it should right, or am I going nuts? (I feel like I am))
Edit 3: Ok even though I feel like I'm talking to myself I'll continue posting my findings. Since the problems seemed to lie with my Google Chrome installation I reinstalled it, problem solved. If someone has some idea of what went wrong I'm all ears, until then I'm finally continuing on my project haha..
I ran into same issues, chrome extention doesnt support websql, only index db.
https://github.com/angular-pouchdb/angular-pouchdb/issues/63
you can try this to get the DB sizing etc.
db.info().then(function (resp) {
//resp will contain disk_size
})

merge large existing web app into Sailjs site

I'm trying to merge large existing web app into sails.js. so I moved the folders into assets and build a custom route , 'GET /': '/assets/client/launch.html' and get 404 when I point my browser to http://localhost:1337/ as the / is correctly redirected to http://localhost:1337/assets/client/launch.html which produces the 404.
Now the file exists in the folder assets/client (and in .tmp), so I am thinking the Sails router is getting in the way.
I would leave the client (70K lines of JS) that generates all the UI dynamically and sailjs server that provides authentication separate and enable CORS but my customer wants client packaged with server. This type of operation is simple in frameworks like ASP.NET MVC but am wondering if Sails is up to the task.
Well, If everything you tried did not work out. There might be another solution ,
First of all since you are talking about sails app I am assuming other bundle must be sails as well ,
So here is what you do-
Change the port for another app that you want to attach to this.
Second whenever you want to go to page on another app simply redirect the client to another port ie
in html or esp put a href tag with different port.
<a href="localhost:PORT/route_to_file">
</a>
I got it working by placing my app into assets where we need to launch from assets/client/index.html as there would be too many dependencies to change. As I said above could not just add a route as Sails must getting in the way. However as in Chapter 3.2.2 of Sails in Action I generated a static asset npm install sails-generate-static --save. then I redirected to assets/client/index.html. As an aside that book is great and would highly recommend it.