Closed jsdream closed 8 years ago
Hi jsdream,
There is not currently a way to require fields in a document, but it's on the todo list. I'd be happy to accept a pull request, otherwise I could probably get to this sometime in the next day or two.
Thanks!
Scott
Thanks for the quick response @scottwrobinson!
I'm happy to hear that it's on the todo list. I'll see if I can find some nice implementation of the feature and maybe will submit a pull request then.
Kind Regards, Vlad
Awesome, sounds good. You'll probably want to add the check in the validate()
function in base-document.js.
If you need help just let me know. Otherwise I'll try to get to it asap. Thanks for the help!
Scott
Hello @scottwrobinson!
Today I started looking into the project, but stuck at the very beginning. I've wrote some simple script to test camo API:
"use strict";
var camo = require('./index');
var connect = camo.connect;
var database;
var uri = 'mongodb://localhost/camo_test';
var Document = camo.Document;
connect(uri).then(function(db) {
database = db;
}, function(err) {
console.log('err', err);
});
class Company extends Document {
constructor() {
super('companies');
this.name = String;
this.valuation = {
type: Number,
default: 10000000000,
min: 0
};
this.employees = [String];
this.dateFounded = {
type: Date,
default: Date.now
};
}
}
function createTestDocument () {
var inzite = Company.create({name: "Vlad"});
inzite.save().then(function(company) {
console.log(company.id);
}, function(err) {
console.log(err);
});
}
setTimeout(createTestDocument, 1000);
But when I try to run it I'm getting the following error:
E:\camo\lib\proxyShim.js:2045
throw new Error("proxies not supported on this platform");
^
Error: proxies not supported on this platform
at new global.Proxy (E:\camo\lib\proxyShim.js:2045:11)
at Function._instantiate (E:\camo\lib\base-document.js:253:16)
at Function.createIndexes (E:\camo\lib\document.js:341:29)
at Function.create (E:\camo\lib\base-document.js:239:14)
at createTestDocument [as _onTimeout] (E:\camo\test.js:36:26)
at Timer.listOnTimeout (timers.js:92:15)
I'm running it on Node v4.2.3.
Any thoughts on this?
Kind Regards, Vlad
Hi,
Since Camo uses Proxy
underneath, you have to run your script with the --harmony-proxies
flag:
$ node --harmony-proxies index.js
I'd like to get rid of the proxies if possible since they're still hidden under the harmony flag, but I haven't looked too deep in to it yet.
Scott
Hi,
That worked for me. Thanks Scott! Actually just noticed this in README file. Sorry for being inattentive! And yes, it would be nice to get rid of proxies if possible :)
Kind Regards, Vlad
No problem at all. The --harmony-proxies
flag isn't very common, so it's
understandable to overlook it.
Let me know if you have any other questions.
Scott
On Tue, Dec 8, 2015 at 4:08 PM, Vladyslav Mashkin notifications@github.com wrote:
Hi,
That worked for me. Thanks Scott! Actually just noticed this in README file. Sorry for being inattentive! And yes, it would be nice to get rid of proxies if possible :)
Kind Regards, Vlad
— Reply to this email directly or view it on GitHub https://github.com/scottwrobinson/camo/issues/18#issuecomment-163033786.
FYI I was able to get rid of the dependency on Proxy in the latest version, so no more need for --harmony-proxies
:smile:
Awesome news! Thanks :+1:
Hello there!
As I can see from the docs there is no currently direct way to specify that some field in document is required. Am I right?
If so I would like to request this functionality or even happy to make a pull request if you would accept one :)