w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
MongoDB: How to define a schema?
You have already been taught that MongoDB is schemaless. However, in practice, we have a kind of "schema", and that is the object space of the object, whose relations a MongoDB database represents. With the ceveat that Ruby is my go-to language, and that I make no claims about exhaustiveness of this answer, I recommend to try two pieces of software: 1. ActiveRecord (part of Rails) 2. Mongoid (standalone MongoDB "schema", or rather, object persistence system in Ruby) Expect a learning curve, though. I hope that others will point you to solutions in other great languages outside my expertise, such as Python.

Categories : Mongodb

cant come up with a good mongodb schema
I would do the following based on what knowledge I have of your application: There are two entities that should exist in two different collections: user and uploads. The uploads collection will be very large, so we want to make sure we can index and shard the collection to handle the scale and performance required by your queries. With that said, some key elements in uploads are: uploads= { _id:uploadId user:{id:userId, emailverified:true, banned:false} ts:uploadTime . . . } possible indexes: i. {ts:1,banned:1,"user.emailverified":1,"user.banned":1} (this index should be multi-purpose) ii. {"user.id":1,ts:1} Note that I store some redundant data to optimize your latest 1000 query. The cost is that in the rare case where emailverified and banned have to be updated, you need to run

Categories : Mongodb

Advice on MongoDB schema design
I would suggest to store notes as you described and additionally store all used tags in user document. Remember that data redundancy is acceptable in MongoDB and very often is the best way to go since you should design your schema for reads, not for writes. Then on the Java side you just store tags in Set as a property of User class so you can be sure to store unique data there.

Categories : Database

MongoDB backup after schema was changed
MongoDB does not enforce a schema. You can easily restore your old documents into the same collection as your new ones. You can write your application to expect old-style or new-style documents when you query them. Or you could use update with operators like set or rename to update the old-style documents and make them conform to the new schema.

Categories : Mongodb

using mongodb for building database with schema
A finer answer to your question would involve explaining things that make up the database. Not every database (not necessarily relational) has the features mentioned below Eventual consistency Referential integrity Linking between objects Metadata attached to data objects In-built Sharding through hashing Transaction isloation ... and so on An application should use a database that best helps it perform its raison d'etre. There is no single database that can fit the bill for all use cases. In fact certain no-sql stores do not even have a concept of 'transactions'.

Categories : Java

Advice on collection schema for MongoDB
If you need fast queries: I think your schema is more or less Ok. If you need fast updates: I would instead refer to the parents using their _id to convert player collection into people collection. In this way if parents change you only update one document and not as many as players having this parent. Keep in mind that, even if you need fast queries, this is not very maintainable because you may have, as you say, duplicate data and this can lead to data inconsistencies.

Categories : Mongodb

Schema design for accumulated data on mongodb
I got! I created 3 colletions: accumulated_stats: :_id, :photos, :documents monthly_stats: :_id, date, :counts {:photos, :documents}, accumulated {:photos, :documents} daily_stats: :_id, date, :counts {:photos, :documents}, accumulated {:photos, :documents} Now, for each action, i will increment accumulated_stats, get the results and increment daily and monthly stats. it works as well! But for showing the data.. i won't have all date time.. for instance: 2013-09-10 2013-09-11 ( do not have ) 2013-09-12 2013-09-13 I'm looking for a way to construct the perfect date range. For instance, i don't have the day 11 on my collection, how can i bring it with the last existent values? any ideas? Thanks, Diego

Categories : Mongodb

How can I work with translated strings in my schema in mongodb?
There are two ways you can go. One, like you have indicated, is called "Denormalization" where you save the category information (the name in each language) in the Product document itself. That way, when you load a Product, you already have the name in each language. You could model a Product like this: { _id: ObjectId(""), name: "MyProduct", category: { Catid: ObjectId(""), names: { en: "MyCategory", es: "...", fr: "..." } } } The other option, if the category name changes too much or you add languages regularly, is to not save the names on the category names on the product, but to rather do a query on the Category collection for the Category when you need it.

Categories : Mongodb

How to read schema-less documents using Java from MongoDB
The java driver reads and writes documents as BasicBSONObjects, which implement and are used as Map<String, Object>. Your application code is then responsible for reading this map and casting the values to the appropriate types. A mapping framework like Morphia or Spring MongoDB can help you to convert BSONObject to your classes and vice versa. When you want to do this yourself, you could use a Factory method which takes a BasicBSONObject, checks which keys and values it has, uses this information to create an object of the appropriate class and returns it.

Categories : Java

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

MongoDB schema design - huge list
Since the orders collection represents a single restaurant would it not instead contain a record of all orders, with each document looking like: { _id:{} waiter: 'Sammaye', table: 9, items: [ {id:9,qty:1,cooked:false} ], billed: false } And all waiters who need to know about orders waiting to go out will just get all order documents from this collection which have billed false. This should be fine enough if you place an index on billed. Using the other method you said could cause problems, for example it is one document in a collection storing all orders. I could imagine in time that document could get quite large. Using in memory operators ($push,$pull etc) could make operations on the document slow. It could also create fragmentation within the dat

Categories : Javascript

Mongodb Schema considering sub-document to avoid multiple reads
Unless your using employee groups (Accounting, HR, etc) You'll probably be fine adding the employee name, mongo Object ID, and any other information unique to that manager / employee relationship as a sub document to the managers document. With that in place you could probably do your reporting on these relationships through a simple aggregation. This is all IMHO, and begs the question; Is simple aggregation another oxymoron like military intelligence?

Categories : Mongodb

MongoDb opening hours Schema and query for open/closed
Instead of using actual hours, rather store your time as 0 - 1440, each number being an increment of a minute. Then you'll be able to use $gte and $lte. So you'd have: hours: { mon: {open: 570, close: 1080 }, tue: {open: 570, close: 1050 }, ... } That's the strategy that I'm using in my app. Of course there are slightly more efficient ways, like storing all the hours for the week in a single array, but your approach is still good.

Categories : Mongodb

Populate MongoDB Document schema object format using Node and MongoosJS
Turned out to be ridiculously simple, by using dot notation as the parameter, and some tweaks to the schema I use. User.find({}, function(err, doc){ callback(doc); }).populate("apps.id"); I am now getting { "_id": "520bb759e4b0845c7706b271", "fname": "Jane", "lname": "Doe", "role": "2", "apps": [ { "id": { "_id": "5208ed90e4b0b41ab826ac9f", "name": "App", "route": "app", "icon": "http://placehold.it/80x80&text=[App]", "rating": 4, "description": "Bacon ipsum dolor sit amet nulla ham qui sint exercitation eiusmod commodo, chuck duis velit. Aute in reprehenderit, dolore aliqua non est magna in labore pig pork biltong." }, "pinned": true } ] }

Categories : Mongodb

MongoDB schema design to support editing subdocuments within an array in multi-user environment?
Having different writers is a key downside of embedding documents in my opinion. You might want to take a look at this discussion that presents different solutions. I'd try to avoid different writers to one document and use a separate Comments collection instead, where each comment is owned by its author. You can fetch all comments on a post by an indexed field postId reasonably fast. Then the comments simply have a regular _id field. It makes sense to use an ObjectId because that automatically stores the time the comment was created, and it's a monotonic index by default. create a "lastModified" timestamp on the parent document, and only save the edit if nothing has changed on the document. This is called 'optimistic locking' and it's generally not good if there is a high probabilit

Categories : Mongodb

Adding private chat functionality to simple twisted chat server
Actually I figured it out by changing the for loop in handle_CHAT. As I want the program to send the message to the specific user, a "talkwith" string can be added to the class and this string can hold that specific user's name. Then this change turns the program from public to private chatting. msg = "<%s> %s" % (self.name,msg) for name,protocol in self.users.iteritems(): if name == self.talkwith: protocol.sendLine(msg)

Categories : Python

Swing chat window creates extra chat windows
Just remove the static keyword from private static UDPCS1 chat = new UDPCS1(); and no more chat windows will be there... Hoping it helped... Helped in my case i was doing something too,...

Categories : Java

PHP AJAX chat - Chat commands logic?
You need to define a syntax for your commands yourself. For example /ban <username> for a ban. First you check whether the message begins with a slash. If so it is a command. Now search for the first space, everything after the slash and in front of the space is the command name. Pass everything after the first space to the command. In this case the username. The command handles the parameters on it's own. It could look like this: $message = '/ban TimWolla'; if (substr($message, 0, 1) === '/') { // $message is a command $firstSpace = strpos($message, ' '); $command = substr($message, 1, $firstSpace); $parameters = substr($message, $firstSpace + 1); if (!hasPermission($command)) error('Permission denied'); switch ($command) { case 'ban':

Categories : PHP

which is faster, saving chat history in a text file and display it or using mysql db to save chat history
For a real-world implementation, I wouldn't consider either one of these a good option, but it definitely could be fun to play with. Using files isn't going to scale as well as the db,well... as easily. But really, I'd look into just setting up a jabber server and play with that. Or maybe look into node.js.

Categories : PHP

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

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

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#

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

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

Pop up chat box on new chat message
Web sockets tends to be the way to go for chat applications, in your case it sounds like server sent events could be perfect (as from what it sounds you're only receiving events, for two way communication you'll be good using web sockets), both lack support in older browser. So if you need to support older browsers you can go with long polling which out of your choices has the least load on the server as it's one request for every response. See this post: What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet? for more info on the specific technologies

Categories : PHP

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

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

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

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

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 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

MongoDB errors: mongodb-10gen E: Sub-process /usr/bin/dpkg returned an error code (1)
This is due to some corruption within the package manager dpkg itself, this thread from Ask Ubuntu: http://askubuntu.com/questions/195950/package-system-broken-e-sub-process-usr-bin-dpkg-returned-an-error-code-1 lists some solutions, more specifically the editing of the status file has been noted as one that always works.

Categories : Linux

Nodejs, MongoDB (node-mongodb-native). FindAndModify finds doc, but doesn't update it
In findAndModify, there is one more parameter which you can set, to return the old document(before update) or new document ( after update ). I am guessing this must be the issue. For confirmation, for the existing findAndModify() command, after this command is run, check that updated document from the mongo console, it must be changed.

Categories : Node Js

Connecting from WSO2DSS to MongoDB, receiving error: java.lang.NoClassDefFoundError: com/mongodb/ServerAddres.
The missing class looks like ServerAddress (I assume the missing "s" is a copy-paste issue) which is in the MongoDB Java driver (mongo-java-driver). Make sure mongo-java-driver-2.xx.jar is on the runtime classpath. Note that the runtime classpath is not always the same as the compile time classpath.

Categories : Mongodb

query based on matching elements in DBRef list for mongodb using spring-data-mongodb
Querying for one element on an array is exactly like query for a field equality. You could read the MongoDB documentation here. So your query will be: new Query(Criteria.where("users.$id").is(new ObjectId(userId)))

Categories : Mongodb

mongodb: java: How to update a field in MongoDB using expression with existing value
At the moment, MongoDB doesn't allow you to update the value of a field according to an existing value of a field. Which means, you can't do the following SQL: UPDATE foo SET field1 = field1 / 2; In MongoDB, you will need to do this in your application, but be aware that this is no longer an atomic operation as you need to read and then write.

Categories : Java

NoSQLUnit MongoDB test: Spring Data MongoDB approach
Jaranda, Seems that your spring repository and nosqlunit are working on different databases. Try to modify your spring configuration to use the same database of nosqlunit. <mongo:db-factory id="mongoDbFactory" mongo-ref="mongo" dbname="test" />

Categories : Java

MapReduce, MongoDB and node-mongodb-native
The reason why the reduce function is never called is due to you emitting a single value for each key so there is no reason for the reduce function to actually execute. Here is an example of how you trigger the reduce function collection.insert([{group: 1, price:41}, {group: 1, price:22}, {group: 2, price:12}], {w:1}, function(err, r) { // String functions var map = function() { emit(this.group, this.price); }; var reduce = function(key, values) { return Array.sum(values); }; collection.mapReduce( map, reduce, { query:{}, // sort: {'count': -1}, // limit: 10, // jsMode: true, // verbose: false, out: { inline: 1 } }, function(err, results) { console.log("----------- 0") console.dir(er

Categories : Mongodb

how to use client chat on different pc
If you are launching your client by running the ClientTest class then you need to update it to use the server IP. In your current ClientTest code you are connecting to the server using the localhost IP: charlie = new Client("127.0.0.1"); Update it to use the server IP: charlie = new Client("use server IP"); server IP is the IP address of the machine where you are running your Server class.

Categories : Java

Prevent XSS in chat
Don't guess, use a function made for the job: HTTPUtility.HTMLEncode Instead of removing "unsafe" strings, encode any character that might be parsed as HTML into an HTML Entity. If this isn't a web-app, the similar functions can be found in WebUtility.

Categories : C#



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