w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Why doesn't my Mongoose schema method "see" my required object?
I believe the issue is that you've created a circular dependency. Story executes require(config.models) which requires Story again inside index.js. Rather than storing a string and requireing it everywhere, try storing the models directly in config.models: config.js module.exports = { test: 'test', models: require(__dirname + '/models') };

Categories : Node Js

JSON schema draft4 VS JSON schema draft3
If you're interested in a deep dive, you can review a diff between the two drafts on the IETF site. However, if you're looking for a simpler summary of changes, Geraint Luff and Francis Galiegue created a changelog page on the project's github wiki that lists the changes, additions, and removals.

Categories : Json

Referencing another schema in Mongoose
It sounds like the populate method is what your looking for. First make small change to your post schema: var postSchema = new Schema({ name: String, postedBy: {type: mongoose.Schema.Types.ObjectId, ref: 'User'}, dateCreated: Date, comments: [{body:"string", by: mongoose.Schema.Types.ObjectId}], }); Then make your model: var Post = mongoose.model('Post', postSchema); Then, when you make your query, you can populate references like this: Post.findOne({_id: 123}) .populate('postedBy') .exec(function(err, post) { // do stuff with post });

Categories : Javascript

Mongoose Schema with ObjectId
Are Posts a collection type in your system? If so : var userSchema = new Schema({ twittername: String, twitterID: Number, votedPosts: [{type: Schemas.Types.ObjectId , ref : 'Posts'}] }); Where 'Posts' is the name of your defined Posts model. See http://mongoosejs.com/docs/populate.html

Categories : Mongodb

getting schema attributes from Mongoose Model
Yes, it is possible. Each schema has a paths property, that looks somewhat like this (this is an example of my code): paths: { number: [Object], 'name.first': [Object], 'name.last': [Object], ssn: [Object], birthday: [Object], 'job.company': [Object], 'job.position': [Object], 'address.city': [Object], 'address.state': [Object], 'address.country': [Object], 'address.street': [Object], 'address.number': [Object], 'address.zip': [Object], email: [Object], phones: [Object], tags: [Object], createdBy: [Object], createdAt: [Object], updatedBy: [Object], updatedAt: [Object], meta: [Object], _id: [Object], __v: [Object] } You can access this through an model too. It's under Model.schema.paths.

Categories : Mongodb

Using 'generic' virtual for mongoose schema
For backbone, "id" is it's default idAttribute name, so just don't add any code there and everything will work as intended. For mongoose, the answer boils down to "it's complicated", but the main points are: By default mongoose will give each schema a virtual called "id" which will be the document's _id as a string However, by default .toJSON doesn't include virtuals, so when you send a mongoose document to backbone in the browser, it gets just "_id" and not "id" to quickly get a JSON representation including the virtuals, use myModelInstance.toJSON({virtuals: true}). You'll get both "_id" and "id" You need to read up on the transform options for toObject and toJSON to get a full picture of what you can do and how, but the gist is (based on examples straight from the docs) // specif

Categories : Node Js

Adding 'virtual' variables to a mongoose schema?
This is perfectly possible in mongoose. Check this example, taken from their documentation: var personSchema = new Schema({ name: { first: String, last: String } }); personSchema.virtual('name.full').get(function () { return this.name.first + ' ' + this.name.last; }); console.log('%s is insane', bad.name.full); // Walter White is insane In the above example, the property would not have a setter. To have a setter for this virtual, do this: personSchema.virtual('name.full').get(function () { return this.name.full; }).set(function(name) { var split = name.split(' '); this.name.first = split[0]; this.name.last = split[1]; }); Documentation

Categories : Node Js

How to properly handle mongoose schema migrations?
I am doing migration like this; Let say I have db called Item. On any schema changes, I create anotherdb called ItemTemp and copy all data to ItemTemp. I executed schema change scenario on ItemTemp db. If everything goes well, I schedule db down time. I copy Item to ItemTemp again execute schema change migration and copy all data to Item db. Hope it helps

Categories : Mongodb

Create a schema in mongoose nodejs for one record only
Yes, this is possible without anything special really other than only put 1 document into that collection. I would just leave your default set of configuration settings as a simple javascript object in code and if you find a configuration record in mongo, just use that to override the defaults via _.defaults or similar. For what it's worth, more commonly identifying the blog admin would be stored on the user record, not in a blog configuration object (user.isAdmin = true for a simple case), but either way will work.

Categories : Database

why mocha assertion fails on mongoose.Schema.objectId?
So mongodb ObjectIds in javascript are sadly frustrating in this regard. They are distinct objects resulting in obj1 === obj2 evaluating to false even though the value they represent is identical. There are 3 options: Convert to strings before comparing. I use this a lot because it's so frustrating otherwise. Use the .equals() method they provide: assert.ok(model.organizationId.equals(objId)) Write a custom comparison function that can take null, ObjectIds, or Strings and do the right thing (I've also done this)

Categories : Node Js

Saving mixed schema in mongoose (markModified doesn't seem to work)
The save method is asynchronous, which means you can't be sure it has finished its work the way you write your code now. Use callbacks: results[0].save( function(error){ if (error){ // augh! }else{ console.log(results[0]); // <- yay! the document is definitely saved here // ... } }); //console.log(results[0]); // <- no, we can't be sure results[0] is already saved in this line

Categories : Mongodb

Inserting Object ID's into array in existing Mongoose schema with Node.js
Keep the category names you want to search for in an array { categories: ["cat1", "cat2"] } then you can add an index to it and do a $in query. the current schema is not very good because you cannot look for the category in a single query but need to resolve all the "categories" links first.

Categories : Javascript

DIfference between sub docs and population in Mongoose and doubts about database schema
In answer to part one, the difference is that in a Document-Subdocument scenario the subdocument is stored with the document (as a child document, accessible through the use of dot notation). In the Mongoose populate scenario, a reference is held to a document in another collection. When you tell mongoose to populate what it does is make another query to MongoDB to get this 'subdocument'. The main difference I see is that with the mongoose populate method you cannot query for documents using the 'subdocument' properties, whereas you can with the embedded subdocument model. Edit, subdocument example So in MongoDB you can store the data as nested subdocuments like so: { _id: acbdbd, "property": "value", "subdocumentproperty" : { "param1": 1, "param2": 2

Categories : Mongodb

In SSDT Schema Compare how do I ignore differences in objects of type "Schema"
I hacked it. If you save the compare, you can add this to the file: <PropertyElementName> <Name>Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlSchema</Name> <Value>ExcludedType</Value> </PropertyElementName> You'll see where when you open it. This setting is not in the UI, but is apparently supported.

Categories : Sql Server

Validating a string has the correct XML format using XML schema (The XML schema would allow any element with any attribute)
Well according to me you can try and load the xml using "LoadXml" method of XmlDocument object (just as you have mentioned in your question) and put it in try..catch block. If the xml is not in correct format it will throw an exception. You can check the following link Others might have a better solution though. Regards, Samar

Categories : C#

Soap-error Parsing Schema: can't import schema from unexpected targetNamespace
There are two obvious differences: in PHP you're using SoapServer instead of SoapClient in Python your URL is different than in PHP - you add some userid or something like that /wsdl& + str(uuid.uuid1()) vs. /wsdl

Categories : PHP

Large Database Schema vs Small Schema and a BLOB/CLOB XML
Having worked with large data systems in various database technologies, I would recommend not using XML for the task. The good news is that SQL Server of course supports the XML data type and you can actually run quite complex queries on XML in TSQL. So you don't even need to suck the XML out into your application to make a stored procedure as an example. The problems I've seen with storing serialized data as XML in a relational data store: It is slow. Run some tests with the XML data type in SQL Server and you'll see that examining it in TSQL is quite a bit slower than just bringing back "regular" data. It is too verbose. The size of XML is quite a bit larger than a format like JSON. You'll lose the ability to query the data in TSQL going with JSON, but when objects get big, it's nice

Categories : Sql Server

Is it possible to create an XSD schema for an XSD schema, or place restrictions on element definitions? How?
Nice question! Several points should be made: First, as I guess you already know (though some readers of the question and this answer may not), your schema document 1 is already legal as it sits. So you don't need to modify the schema for schema documents in order to make it legal. If I understand you correctly, however, you want it not just to be valid; you want the variant of it in which element declarations occur without xs:documentation elements, or without ds:added and ds:last_modified attributes, to be invalid. Second, it is possible to modify the XSD schema for XSD schema documents in the way you describe, and it is in principle possible to validate your schema documents against the modified schema for schema documents. But schema validators are allowed to have built-in k

Categories : Xml

Mongoose ignoring part of object unless defined as Schema.Types.Mixed
The type property of attr is likely tripping up Mongoose to thinking attr is a string instead of an embedded object. Use a more explicit definition for the property, like this: attr: appearance: String aroma: String flavor: String from: String grade: String lineage: String name: String overall: String packaging: String pickupdate: String price: String reason: String story: String type: type: String

Categories : Javascript

Failed to read schema document Schema Cloudfoundry
So it looks like your app is working locally and on AppFog, but as you say the issue is a validation error in Eclipse. Are you using the Spring Tool Suite plugin? What should actually happen here is that the schema should be found within the Spring Jar file (the source is on Github https://github.com/cloudfoundry/vcap-java/blob/master/cloudfoundry-runtime/src/main/resources/META-INF/spring.schemas) - I guess there should be a way of telling Eclipse to resolve it there, and I suspect that STS would actually know how to resolve it.

Categories : Java

Can't add keys with dots (key paths) to a Mongoose field with type: Schema.Types.Mixed
Yes, it is. Valid JSON doesn't have dots as far as I know. What you are supposed to do is this: { "character": { "treasure_chests": 1 } } Here is an example: JSON Schema example

Categories : Json

Is it possible to have two Schema imports in one schema with my own root element
First of all, <xs:import> is not supposed to include some piece of XSD into another XSD. It is meant to let the XSD processor know that this particular schema may use components from another (imported) namespace. If you want to reuse some XSD definitions across different schemas (all of which target the same namespace), you should use <xs:include> or <xs:redefine> (<xs:redefine> allows you to change on the fly a few things defined in the included piece). But both <xs:include> and <xs:redefine> can be specified only as direct children of <xs:schema> and only at its beginning. The fact that <xs:schema> is nested in <wsdl:types> doesn't change anything here.

Categories : Xml

XML schema: how to import a global element from another schema?
The import is enough to import the element. Then it just depends what you want to do with it. If you want to make it part of the content model of a complex type, then include an element particle that refers to it, for example <element ref="mon:heartBeatresp"/>, or if you want to add an element to its substitution group, use substitutionGroup="mon:heartBeatresp".

Categories : Xml

How to convert relational schema to Accumulo schema?
There are many ways to store this. Remember, the schema is not rigid. Different rows can follow different patterns. Suppose you have an incident with several comments. Entries might look like this: rowID, cf:cq, v =============== incident|<uuid1>, poc:fullname, bob jones comment|<uuid2>, incident:key, incident|<uuid1> comment|<uuid3>, incident:key, incident|<uuid1> But that approach above would require you to index the comments separately so that you can quickly find all comments belonging to a particular incident. Another approach would be to add a column qualifier to the incident row for each comment. rowID, cf:cq, v =============== incident|<uuid1>, comment|<uuid2>:text, my comment incident|<uuid1>, comment|<uuid3>:text, my

Categories : Misc

Updating XML column schema with new schema
A schema collection should permit you to have different versions of the XML data without having to ignore validation. Have a look at XML Schema Collections to start with. In your T-SQL code, you'd have something like this (this code is sourced from Bob Beauchemin of SQLskills.com): -- Load XML schema from file DECLARE @x XML SET @x = ( SELECT * FROM OPENROWSET( BULK 'C:invoice.xsd', SINGLE_BLOB ) AS x ) -- And use it to create an XML schema collection CREATE XML SCHEMA COLLECTION InvoiceType AS @x Now you create a table which maps the column to the schema collection: CREATE TABLE invoice_docs ( invoiceid INTEGER PRIMARY KEY IDENTITY, invoice XML(document InvoiceType) ) Now when your schema changes, you modify the schema collection by adding in the new vers

Categories : Xml

JSON Schema regarding use of $ref
OK: each $ref is resolved into a full URI. Once that is done, all your questions are answered by asking the question: What schema would I end up with, if I simply fetched that URI? Where the $ref is, how it was loaded, all of that is irrelevant - it's entirely dependent on the resolved URI. The library might take some shortcuts (like caching documents so they are only fetched once, or trusting one schema to "speak for" another), but those are all implementation details. Response to original question: # is not special: all values of $ref are resolved as URIs relative to the current document (or the closest value of "id", if there is one). Therefore, if you haven't used "id", then # will point to the root of the schema document. If you fetched your schema from http://example.com/schem

Categories : Json

How to handle @Ref from XSD in JSON Schema
That form of referencing is correct. It is not the only way to organise things, but it is the way I would recommend. You do have a bug in your schema, though - you have "$ref" directly inside "properties". You are presumably not defining a property called "$ref" in your data, so is this meant to be inside another property declaration?

Categories : Misc

What support is there for json schema in Qt / C++ / C
Indeed, it seems there are no Qt support for JSON Schema validation, even in Qt 5.1. Since writing your own would be very time-consuming, I would suggest: If you as developer would have provided the Schema, then do not validate by using a JSON Schema validation, but instead perform a hard-coded validation of your parsed JSON (i.e., manually check that the required fields are present, are of the correct type, and are within the specified bounds) If handling external JSON Schema is necessary (i.e., the Schema is not known in advance, possibly user-defined), then do not use Qt but an independent C/C++ JSON validator, like WJElement (the one linked on the json-schema website)

Categories : Json

Schema.org ontology as json
No, no official JSON version of schema.org now. But some attempts have been undertaken. E.g. by Google for GMail Actions stuff. They use JSON-LD: <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "Event", "name": "John's Birthday Party", ... information about the event ... "action": { "@type": "RsvpAction", "url": "http://events-organizer.com/rsvp?eventId=123", } } </script> Details are available here. Hope this helps.

Categories : Javascript

constructor from json schema
I found the answer to what I was looking for. My ultimate goal was to make an object with arrays of children, each of which could have children etc. The object would then be used as the namespace to my entire application like: var myobj = {}; I wanted to use JSON to specify the properties of this object, and then build constructors off of these properties like: var myObj = { "name": "genericname", "id": "uniqueid", "children": [ { "grandchildren": [ { "name": "child", "age": "0" } ] } ] }; What I ended up doing was, building constructor functions from this, and then cloning them into my new objects so they could have these default values like this: myObj.Child = function(){ var child = myObj.children[0

Categories : Javascript

Backbone RESTful JSON schema
It looks like the JSON I posted above was correct. The problem was that the JSON I posted was pseudo-code and the JSON that I was actually outputting from my backend system was wrong -- all of the IDs in my output were the same number (copy/paste problem). For anyone looking to create a Backbone / Handlebars app, the code above seems to be a good starting point.

Categories : Json

support for std::map< std::string, T > in json schema
If I wanted to model a structure for users favorites movies (remind Json Schema is intended for structure validation) I would make something like: { "description":"moviesFan", "properties": [ "favoriteMovies": { "type":"array", "uniqueItems":True "allOf": [{ "$ref": "#/definitions/movie" }] } ], "definitions": { "movie": { "type": "object", "properties": { "yearMade": {} ... } } } Does it make sense to you?

Categories : Json

How to validate a form using JSON Schema?
I checked it again in the JSON schema website and it seems the name "Turbidity (ntu)" is not a valid key. JSON schemadoes not 'like' parentheses in a key. It works if you leave the parentheses out, like in "Turbidity ntu". I was just commenting on @pmagunia's entry when he apparently withdrew it. He remarked that required can only contain boolean values. It seems to me that the required property at the top is actually superfluous. I just tested it in JSON Schema Lint and the schema is said to be valid without it. But required can definitely only hold boolean values. Your array [ "TestSite", "Date of Test", "Latitude", "Longitude" ] was transformed by JSON Schema Lint into an unquoted string TestSite,Date of Test,Latitude,Longitude which will definitely be invalid JSON!

Categories : Javascript

Only allow properties that are declared in JSON schema
I believe what you need to do to achieve this is set "additionalProperties" to false. See the specification here: http://json-schema.org/latest/json-schema-validation.html#anchor64

Categories : Json

JSON Schema with dynamic key field in MongoDB
Obviously the second schema example is much better for your task (of course, if lan field is unique as you mentioned, that seems true to me also). Getting element from dictionary/associated array/mapping/whatever_it_is_called_in_your_language is much cheaper than scanning whole array of values (and in current case it's also much efficient from the storage size point of view (remember that all fields are stored in MongoDB as-is, so every record holds the whole key name for json field, not it's representation or index or whatever). My experience shows that MongoDB is mature enough to be used as a main storage for your application, even on high-loads (whatever it means ;) ), and the main problem is how you fight database-level locks (well, we'll wait for promised table-level locks, it'll fa

Categories : Mongodb

Avro Pair Schema In JSON Format
The Schema class has a toString() method that does what you want: import org.apache.avro.Schema; import org.apache.avro.mapred.Pair; public class Test { static final Schema PAIR_SCHEMA; static final String RECORD_STRING = "{ " + " "type": "record", " + " "name": "exampleRecord1", " + " "fields": [ " + " {"name": "id", "type": "string"} " + "] " + "}"; static { final Schema.Parser parser = new Schema.Parser(); Schema KEY_SCHEMA = parser.parse( RECORD_STRING ); Schema VALUE_SCHEMA = Schema.create( Schema.Type.STRING ); PAIR_SCHEMA = Pair.getPairSchema( KEY_SCHEMA, VALUE_SCHEMA ); } public static void main( String[] args ) { System

Categories : Json

setting required on a json-schema array
Maybe your validator only supports JSONSchema v3? The way required works changed between v3 and v4: In v3 required is a boolean: http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7 In v4 required is an array of strings (like in your example): http://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.3

Categories : Json

Nested JSON from Postgres API, schema does not exist?
There's no group_concat in PostgreSQL. You may use string_agg: select h.name, h.h_id, '[' || string_agg('{"src":"' || p.url || '", "caption":"' || p.caption || '"}', ',') || ']' from holidays as h inner join photos as p on h.h_id = p.h_id group by h.name, h.h_id see sql fiddle demo with this example Or use JSON functions. There's also nice JSON support in version 9.3

Categories : SQL

how json schema validate mixed property?
Provided the validation library you're using is based on a relatively recent version of the JSON Schema, you should be able to use patternProperties to validate properties with user-defined keys. Here is a quick example that uses the javascript library tv4 to perform the validation: var schema = { "patternProperties": { "^[a-zA-Z0-9]+$": { "title": "someUserDefinedPropertyName", "type": "number" } } }; var valid = { "a": 1234, "b": 5678 }; var invalid = { "a": "1234", "b": 5678 }; alert("Validates? [should be true]: " + tv4.validate(valid, schema)); alert("Validates? [should be false]: " + tv4.validate(invalid, schema)); alert('Variable invalid, error at data path: ' + tv4.error.dataPath + ' Error Description: ' + tv4.error.message); F

Categories : Json

JSON .Net generates schema incorrectly (type as an array)
It is not an array of strings, it is a nullable string. { "type": [ "string", "null" ] } means that a valus is either a string or null. Array of strings would be { "type": "array", "items": { "type": "string" } }

Categories : Asp Net Mvc



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.