teleren/devto huggingface dataset:
How to find a document in a mongo collection based on whether a field exists or not
Tags: mongodb, showdev, webdev, tutorial
Published: 2020-01-09 11:49:20

---
title: How to find a document in a mongo collection based on whether a field exists or not
published: true
date: 2019-01-09 00:00:00 UTC
tags: ['mongodb', 'showdev', 'webdev', 'tutorial']
canonical_url: https://learnwithparam.com/blog/find-all-documents-in-mongodb-based-on-field-exists-or-not/
description: In NoSQL, you can save the different documents in a single collection. Now if you want to find documents with a specific field, how do you find that? There is an easy way, we will see it in the example.
---

MongoDB find syntax is pretty simple. Lets have a collection named `users` and find all the documents in the collection,

```js
// Query
db.users.find({});

// Result
[
  {
    email: 'one@email.com',
    name: 'one',
  },
  {
    firstName: 'two',
  },
  {
    email: 'three@email.com',
    firstName: 'three',
  },
];
```

If we need to filter by some field then,

```js
// Query
db.users.find({ email: 'one@email.com' });

// Result
[
  {
    email: 'one@email.com',
    name: 'one',
  },
];
```

What if we need to filter all the documents based on a specific field. For example,

- list all the document which don’t have `email` field
- list all documents which have `firstName` field

#### Filter document which doesn’t have email field

It can be easily achieved using `$exists` operator on the field.

```js
// Query
db.users.find({ email: { $exists: false } });

// Result
[
  {
    firstName: 'two',
  },
];
```

#### Filter document which have firstName field

```js
// Query
db.users.find({ firstName: { $exists: true } });

// Result
[
  {
    firstName: 'two',
  },
  {
    email: 'three@email.com',
    firstName: 'three',
  },
];
```

MongoDB is very powerful and it provides a lot of methods to query what you exactly want. Hope you find this tutorial helpful 🤗
How much time would you give to the javascript frameworks?
Tags: react, vue, angular, webcomponents
Published: 2019-01-08 23:46:30

---
title: How much time would you give to the javascript frameworks?
published: true
description: Are javascript frameworks really the future?
tags: react, vue, angular, web components
---

How much time do you think it will take for the native web components to take the place of the big 3 javascript frameworks? From an arhitecture point of view I think javascript frameworks are a bad decision. Commiting to a framework means that your app becomes dependent on that framework, when it should really be the other way around. What do you think?

https://link.medium.com/BeOVAIp3jT
Thoughts on using a game dev engine like godot to develop an app's UI? 
Tags: discuss, gameengine, gui, uiux
Published: 2019-01-08 23:15:24

---
title: Thoughts on using a game dev engine like godot to develop an app's UI? 
published: true
description: discussion on the pros/cons and experiences of using a game development engine to build the user interface of an app.
tags: Discussion, GameEngine, GUI, UI/UX
---
Do backup drills
Tags: database, discuss, devops
Published: 2019-01-08 23:12:52

---
title: Do backup drills
published: true
description: 
tags: meta, database, discuss, devops
---

Story time! Not long ago, (read Christmas) we had an unfortunate event where all our main production data was wiped out because Murphy was being naughty. Phone were ringed, text were sent and finally we converted out backup into the master database. This was not ideal as now we were running without actual backup and at risk of losing everything if one disk fail. The reason we did it this way was very simple, **no one known how the backup system works**.

Now we are back at office and the first order is obviously to fix the situation. The reason no one known how it works is simple, the guy who did it left the company and we never had to use it in a real scenario. To make the matter worse, the solution was build before our Kubernetes stack so we were not using fancy replication toys but instead, a bunch of custom scripts.

As a team, we had to spend around 30 developer hours to understand, propose and fix the problem. After that exercise, half of the team understand how the backup system works and we would probably spend much less time without proper backup.

This event made me reflect on how we NEVER drill backup recovery like how we do for fire emergency. I strongly suggest that any team with a real production server should do backup drill where:
1. A real case is used. For example, delete PostgreSQL data folder while the system is running and serving users.
2. The drill should targets new team member as a learning experience.
3. The drill should highlight potentials confusion or better methods as your stack evolves in time.

Like a fire drill.
State Rules!
Tags: state, conditionalrendering, react
Published: 2019-01-08 22:46:35

---
title: State Rules!
published: true
description: Basic understanding of ‘State’ object system in ReactJS
tags: state, conditional rendering, Reactjs
---

Rules of state
- Do not confuse props with state
- ‘State’ is a JS object
- Only usable with class based components
- State has to be initialized when a component is created
- Never update state directly.
- State can only be updated with setState.
- Updating State causes the component to re-render.

State object is defined inside the constructor function. 
Use states (this.state) to manage dynamic data.

Constructor note
The base class of React.Component has its own constructor and by defining a new constructor, it gets overridden. But to make sure that the “parent” constructor gets called we use super(props). Super with props is a reference to the parent constructor inside React.Component function.
Do novices make quick fixes and experts clean changes?
Tags: discuss
Published: 2019-01-08 22:15:11

---
title: Do novices make quick fixes and experts clean changes?
published: true
tags: discuss
---

> "When debugging, novices insert corrective code; experts remove defective code." - Richard Pattis

Among other things, we discuss this quote in our show this week. In a knee jerk reaction I want to agree, but I think the answer is more nuanced than this.

{% podcast https://dev.to/edaqa-and-stephane-podcast/16-bitcoin-anonymity-wip %}


So what do you think? Is the habit of making quality fixes an expert only trait? Do senior covers even make better fixes?
Simple way to do code splitting for Redux
Tags: javascript, redux
Published: 2019-01-08 21:41:05

---
title: Simple way to do code splitting for Redux
published: true
description: The simple way to code splitting for Redux
tags: javascript, redux
---

Most of documentation, tutorials, youtube videos taught you how to create your own Redux Store. It's sweet. But let's make it better.

How about you want to do code splitting with your Redux store ?

By code splitting Redux store, i mean, in some cases, you don't want to import all of your Redux actions to be used in a React component, for example, on `/login` page, you just want to import `login` action only.

The solution is dead simple !

Just use the old school `window.REDUX_STORE_LOGIN` for `/login` route.

```
window.REDUX_STORE_LOGIN = createStore(...)
```
Do this when user is accessing `/login` route.

And do the same for all of your routes to split your Redux store to the max.

Happy reduxing!
"How" do you study?
Tags: discuss
Published: 2019-01-08 20:23:37

---
title: "How" do you study?
published: true
description: Questions about how do you study (when, where, how much...)
tags: discuss
---

We all have to study. Everything changes constantly. We have works, responsibilities, families, we all have to seek a healthy life so we have to sleep well, and all of that takes time, and when you are decided to study you will have 2 options:
1 - Smile with an opportunity to grow up not just as a professional but as a human being
2 - Get angry and make dumb decisions

So, because you want the 1st option, how do you study? This question leads to other questions:
1 - How do you decide what to study?
2 - How do you prepare your schedule for studying? (because you will have to move things, cancel others)
3 - How do you prepare your environment to protect you to not get distracted?
4 - What tools do you use for studying?
5 - Whats your methodology for studying?
Oracle and SQLite compiler are now available in SqlKata
Tags: sql, sqlite, oracle, c
Published: 2019-01-08 19:53:02

---
title: Oracle and SQLite compiler are now available in SqlKata
published: true
description: Announcing new compilers for SqlKata
tags: Sql,SQLite, Oracle, C#
---
https://medium.com/@ahmadmoussawi/oracle-sqlite-and-firebird-compilers-are-now-available-for-sqlkata-262b80de206e
Need help finding a very basic vanilla Javascript SPA router tutorial or source code
Tags: vanilla, javascript, spa, router
Published: 2019-01-08 19:39:37

I am coding a very simple single-page-app (actually just a website with one page) that is responsive to all screen sizes. It won't need to be a Swiss Army Knife like most libraries or apps try to be. I will be using no libraries/frameworks/tools other than Autoprefixer, Normalize, Ionic Icons, Font Awesome, Google Fonts, and other minimal use of miscellaneous libraries or tools.

Yes you heard it right. There will be no Node or Grunt or React or Vue or Backbone, and certainly no jQuery (goes against every fiber in my body). I am well aware that building even the simplest SPA can be a very daunting challenge but my app will only be a very elementary personal web page to showcase my online portfolio (mechanical engineering) of information about me and projects I have worked on as well as javascript calculators I am developing for solving problems in engineering.

I will still follow best practices such as accessibility, linting, minimizing, prefixing, tree shaking, W3C and ECMA standards, and compacting all source code but I won't Babel because that is not necessary for my intended purpose. I have the HTML, CSS, Javascript, DOM, BOM, JSON, and AJAX pretty much figured out. It's just the router that I really need help with. I really don't know where to start. A good tutorial, online book, books for purchase, or complete source code in vanilla Javascript would be very helpful. Please no jQuery.

Thank you for your time.
Changelog: Collapse Comments (via the `details` HTML tag)
Tags: meta, changelog, webdev, html
Published: 2019-01-08 19:39:29

---
title: Changelog: Collapse Comments (via the `details` HTML tag)
published: true
description: 
tags: meta, changelog, webdev, html
---

You can now collapse comments by clicking on the ▼ symbol that appears near comments.

It is not 100% rolled out, as we'll let some caches clear naturally to display the new functionality. We may also need to make some small adjustments to click area radius and the such.

This feature was built using the nifty `<details>` tag, so the mechanism is not triggered by JavaScript.

Thanks to @Link2Twenty for pitching this approach in this issue:

{% github https://github.com/thepracticaldev/dev.to/issues/173 %}

Happy coding ❤️
Print default values of CLI arguments in Python
Tags: python
Published: 2019-07-02 21:48:05

---
title: Print default values of CLI arguments in Python
published: true
tags: python
canonical_url: https://ofdigitalwater.postach.io/post/print-default-values-of-cli-arguments-in-python
---

If you would like to print default values of command-line arguments and if you use the `argparse.ArgumentParser` class in your Python program, consider setting the `formatter_class` option to `argparse.ArgumentDefaultsHelpFormatter`.

Example code:

```python
parser = argparse.ArgumentParser(description=sys.modules[__name__]. __doc__ ,
                                 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-s', '--std', type=float, default=440.0, help='Standard value')
args = parser.parse_args()
```
GitHub Private Repos are Now Free
Tags: github, reactnative, webdev
Published: 2019-01-09 05:52:23

---
title: GitHub Private Repos are Now Free
published: true
tags: github,REACT,React Native,web development
canonical_url: 
---
--------------------------------------------------------------------------
Source : <a href="https://www.skptricks.com/2019/01/github-private-repos-are-now-free.html" > GitHub Private Repos Are Now Free </a>
--------------------------------------------------------------------------

The announcement of free private repositories probably took some of GitHub’s competitors by surprise, but here is what we heard from GitLab CEO Sid Sijbrandij: “GitHub today announced the launch of free private repositories with up to three collaborators. GitLab has offered unlimited collaborators on private repositories since the beginning.We believe Microsoft is focusing more on generating revenue with Azure and less on charging for DevOps software. At GitLab, we believe in a multi-cloud future where organizations use multiple public cloud platforms.”  
  

> You can add up to three collaborators to each private repo. There's also some other news related to the other pricing levels they have.

[![GitHub Private Repos are Now Free](https://1.bp.blogspot.com/-KVciGbT9hYA/XDToF9ZDVLI/AAAAAAAACTs/pwmD-z3L1t8HaFoObaQysmfm9Ls5LZjRQCLcBGAs/s640/github.png "GitHub Private Repos are Now Free")](https://1.bp.blogspot.com/-KVciGbT9hYA/XDToF9ZDVLI/AAAAAAAACTs/pwmD-z3L1t8HaFoObaQysmfm9Ls5LZjRQCLcBGAs/s1600/github.png)
  
Let me know your thought in comment box below...
In-Browser Crypto Mining (With Permission) As A Way To Monetize Traffic?
Tags: discuss, webdev, monero, crypto
Published: 2019-01-08 18:05:35

---
title: In-Browser Crypto Mining (With Permission) As A Way To Monetize Traffic?
published: true
description: 
tags: discuss, webdev, monero, crypto
cover_image: https://images.unsplash.com/photo-1516245834210-c4c142787335
---

_I know you can't browser mine [BTC](https://unsplash.com/photos/JrjhtBJ-pGU), but [Unsplash](https://unsplash.com/jackharner) didn't have any XMR pictures_

Obviously cryptojacking is a bad practice and should be whole-heartedly frowned upon but what about if you ask permission first? 

![AuthedMine Permission Pop Up](https://thepracticaldev.s3.amazonaws.com/i/a6e43nccpq2tmwps1kl5.png)

With the rise of AdBlockers, AdSense and the like are probably falling off as good ways to monetize a website.

I'd love to hear the DEV community's thoughts on the matter. Is this a viable monetization option? Does getting permission first make a difference? Is anybody using in-browser crypto mining and had any success with it? Is it still "malware" if you ask permission first?
Suggest best resources to learn VueJs from Scratch 
Tags: vue, beginners, bestcourse, php
Published: 2019-01-08 17:57:24

---
title: Suggest best resources to learn VueJs from Scratch 
published: true
tags: vuejs, beginner, best course, php
cover_image: https://thepracticaldev.s3.amazonaws.com/i/2tpwyhpwdz19fklwesrf.png
---

I am writing an article for those who are just starting or interested to learn VueJs.

I hope as a Top VueJs expert, you will suggest best resources to learn VueJs from your side.
Really easy way to use HTTPS on localhost
Tags: githunt, ssl
Published: 2019-01-08 17:24:08

Testing if your site works well on your local machine is always burdensome.

I found a tool that makes it really simple, [mkcert](https://github.com/FiloSottile/mkcert):

```shell
➜  localhost-https mkcert -install
Using the local CA at "/Users/.../mkcert" ✨
The local CA is now installed in the system trust store! ⚡️
The local CA is now installed in the Firefox trust store (requires browser restart)! 🦊
The local CA is now installed in Java''s trust store! ☕️

➜  localhost-https mkcert localhost
Using the local CA at "/Users/.../mkcert" ✨

Created a new certificate valid for the following names 📜
 - "localhost"

The certificate is at "./localhost.pem" and the key at "./localhost-key.pem" ✅
```

Then you can test with a simple HTML page:

```shell
➜  localhost-https cat index.html
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: index.html
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ <html>
   2   │ <body>
   3   │ HELLO WORLD
   4   │ </body>
   5   │ </html>
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
➜  localhost-https ./node_modules/http-server/bin/http-server -S -C ./localhost.pem -K ./localhost-key.pem                                                                                                                         [18:12:41]
Starting up http-server, serving ./ through https
Available on:
  https://127.0.0.1:8080
  https://192.168.1.69:8080
Hit CTRL-C to stop the server
```

this is the result:

![](https://thepracticaldev.s3.amazonaws.com/i/1z5km8xkhgqqwgyrm80i.png)

{% github FiloSottile/mkcert %}
Stop, Let's Talk Before You Flag that Feature
Tags: featureflag, devops
Published: 2019-01-08 17:13:18

---
title: Stop, Let's Talk Before You Flag that Feature
published: true
description: I don't recommend going down the feature flag workflow. 
tags: featureflag, devops
---

[Feature flags] (https://itnext.io/feature-flags-be-truly-agile-820ff50294c) are making their rounds and I want to step in. 

When you read the linked article it has a section for the bad, not being able to use a feature toggle is not a con to list against it. You will also see it is great for QA because you can break up you QA into feature testers.

Let me give you the actual cost of feature flags.

* You're adding non-production logic to your code
* QA now has more software versions to test

I think the first is pretty clear, more code means more chance for bugs, modifying existing code to provide toggling which would not have needed modified otherwise increases change, change equates to increase risk.

QA does not need more variables to control for. There is is an [algorithm](https://dlang.org/phobos/std_algorithm_setops.html#.Cartesian Product) to help you calculate all your new test scenarios. Here is the best part, we aren't going to test them all. 

Feature flags can work and they can work well. But there are other software development practices to follow before it will even have a chance of not creating a huge mess. 

One of the touted QA benefits was a broken environment taking days to fix. To be clear that commit/merge needs reverted ASAP.

Feature flags increase risk, especially if used the way touted by this article. A/B testing on the other hand has the same issues but you were told about needing extra production monitoring.
My take on dynamodb
Tags: dynamodb, aws, nosql
Published: 2019-01-08 17:01:11

---
title: My take on dynamodb
published: true
description: I explored dynamodb in more detail, here's what I think.
tags: dynamodb,aws,nosql
cover_image: https://thepracticaldev.s3.amazonaws.com/i/xsnznqkeo1ixnep7kdvr.png
---

# Why Dynamodb

Every time I look at the Dynamodb SDK docs, I think 'man this is an over engineered hot mess'.  The obvious reasons to use dynamodb are that it is managed, has autoscaling built in, and it's cheap.  The technical idea is that compute (i.e. mysql) is much more expensive than mapped storage (i.e. dynamodb).

# Why might I use it

Using it as a key value store, `1:1`, or a time series data source, `1:N`, are clear and easy to implement.  I'm of the opinion that this is probably all you should consider using it for.  If you need `N:M`, you need to add a "Global Secondary Key" which is like a higher order clone of your main table's items which doesn't require uniqueness on the partition key.  If you need `N:M:O`, just use a relational database.

# Take-aways on reading data

### Scans

![scan abilities](https://thepracticaldev.s3.amazonaws.com/i/v3pjb7gt5d9pvdmfvti2.png)

Use scans when you don't know the partition key.  You probably want to reserve this operation for "data-science" reasons.  Scan will go through *all* of the data.  If you don't have a lot of data (< 10GB), do whatever you want.

### Queries

![query abilities](https://thepracticaldev.s3.amazonaws.com/i/9i8xiq8knge3cavjcx98.png)

Use queries when you know the partition key and want to sort on the sort key.

### Filters

![filter abilities](https://thepracticaldev.s3.amazonaws.com/i/9rxz0o95gqf22k75zx5f.png)

Filters can be applied to either scans or queries.  They happen _after_ the scan or query completes.  A query and filters can be a powerful combination, such as filtering a product list by brand or price.

### Get Item

Interestingly the AWS console does not have a get item option.  This is probably because a query can solve this operation.  Using this method is obviously going to return 1 record and be most efficient on all fronts.

# Create, update, delete

These are pretty generic operations on an atomic level.  If you need to batch an operation, there are methods in the SDK for those.

# A use case I like

User sessions I think are an interesting candidate for the `1:1` or `1:N` use case.  Data will be automatically encrypted at rest.  Dynamodb tables can also be configured to have TTL on items.  In the `1:N` scenario, if a logout action happens and you set the sort key to contain a user id, you can remove all sessions at once.
Picking the Right Standards for Innovation
Tags: discuss
Published: 2019-01-08 16:32:58

---
title: Picking the Right Standards for Innovation
published: true
description: Consider the bounds of standards and allow for controlled exploration.
tags: discussion
series: standards
---

Standards are good, I don't ever want to come across as I don't believe in standards. But trouble can be had if the focus of standardizing targets the wrong things. It is standard practice to re-evaluate the standards every time they are using, including this standard.

[Do Standards Hinder Innovation](http://www.innovationmanagement.se/imtool-articles/do-standards-hinder-innovation/). I would say this falls into the everything category, everything in moderation... even moderation (as my wife likes to say). If you're choosing standards because they are standard, you're doing it wrong. Are you choosing them because you know standards exist for a reason... can you articulate that reason?

By definition standards are not innovation, if you have a core tenant that your company is an innovator... you best not be doing the standard, best practices. This doesn't mean standards shouldn't exist, it means you want people to break from the standards. You want those standards to be challenged. You don't want standards to be the way we've always done it.

[Rant] On my behalf the argument was made that the code had been around for years, because the concern was that it would be problematic as selenium changes. This didn't go over too well, "we've always done it that way" isn't a reasonable excuse. This creates a massive conflict, innovation, standards, not doing it the same as before, establishing repeatable practices but never do them again.